Re: how to browse values from a GtkListStore ?
- From: Carlos Pereira <jose carlos pereira ist utl pt>
- To: gtk-app-devel-list gnome org
- Subject: Re: how to browse values from a GtkListStore ?
- Date: Sun, 15 Nov 2009 22:16:08 +0000
Let's say you would like to retrieve some information for the selected
row, not just the string name. You could add a (hidden) column to your
store, with that information, and then get it back with
gtk_tree_model_get. Let's say you would like to have a pointer to a
function, for each of your rows, you would have something like this:
treeview = gtk_tree_view_new ();
...
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("My_Title", renderer,
"text", 0, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
/* treeview has 1 column, list_store has 2 columns */
store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
...
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, label0, 1, function, -1);
...
gtk_tree_view_set_model (treeview, store);
g_object_unref (store);
}
and then your callback would look like this:
void my_callback (GtkTreeView *treeview,
GtkTreePath *path, GtkTreeViewColumn *col, void *data)
{
model = gtk_tree_view_get_model (treeview);
if (gtk_tree_model_get_iter (model, &iter, path) == FALSE) return;
/* get and execute pointer to function */
gtk_tree_model_get (model, &iter, 1, &function, -1);
(* function) (data);
}
Carlos
To retrieve string from store, simply use
something like this:
---- CODE ----
gchar *string;
gtk_tree_model_get( GTK_TREE_MODEL( store ), &iter, 0, &string, -1 );
/* Do something with string here */
g_free( string );
---- CODE ----
Works. Thanks for your help
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]