How to retrieve the data of the selected row in TreeView containing GtkListStore
- From: <chenjun1 egr msu edu>
- To: <gtk-app-devel-list gnome org>
- Subject: How to retrieve the data of the selected row in TreeView containing GtkListStore
- Date: Sun, 23 Nov 2003 03:04:16 -0000
Hi, dear all,
I'm trying to retrieve the data of the selected row in TreeView containing
GtkListStore.But not succeded. Is it possible to finish this
functionality? Is there something wrong with my code? or will you just
give a example having that functionality.
thanks a lot,
Jun
GtkListStore *fileListStore;
GtkWidget *fileTree;
main()
{
fileListStore = gtk_list_store_new (1, G_TYPE_STRING);
//insert items into list
gtk_list_store_append (fileListStore, &fileIter);
gtk_list_store_set(fileListStore, &fileIter, 0, "spacemusic.sb", -1);
fileTree = gtk_tree_view_new();
gtk_tree_view_set_model(GTK_TREE_VIEW(fileTree),
GTK_TREE_MODEL(fileListStore));
fileRenderer = gtk_cell_renderer_text_new();
fileColumn = gtk_tree_view_column_new_with_attributes("Name",
fileRenderer,"text",0, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(fileTree), fileColumn);
gtk_container_add (GTK_CONTAINER (fileScrolledWindow), fileTree);
gtk_widget_show (fileTree);
}
//button clicked function
{
GtkTreeSelection* TreeSelection;
GtkTreeIter iter;
GtkTreeModel *model;
TreeSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW(fileTree));
if(gtk_tree_selection_get_selected (TreeSelection,
&model,
&iter))
{
char *str;
gtk_tree_model_get_value(model, &iter,
0, &str);
g_print ("%s\n", str);
g_free (str);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]