Re: Getting row numbers
- From: David Nečas (Yeti) <yeti physics muni cz>
- To: gtk-list gnome org
- Subject: Re: Getting row numbers
- Date: Wed, 9 May 2007 16:55:47 +0200
On Wed, May 09, 2007 at 07:23:18AM -0400, tj wrote:
> I am having a terrible time trying to get the selected row number from a tree view, and it seems so easy using gtk_tree_selection_get_selected_rows();
>
> Snippet of code:
>
> const gchar* txt;
> GtkTreeSelection *selection;
> GtkTreeModel *model;
> GtkTreeIter iter;
> GtkTreeView* list = GTK_TREE_VIEW(lookup_widget(myWidget,
> "theList"));
>
> selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
> if (gtk_tree_selection_get_selected(selection, &model, &iter)){
> gchar *name;
>
> gtk_tree_model_get (model, &iter, 1, &name, -1);
>
> g_print ("selected row is: %s\n", name);
>
> g_free(name);
> }
> else{
> g_print ("no row selected.\n");
> }
> g_print("Number of selected rows = %d\n",
> gtk_tree_selection_count_selected_rows(selection))
> ;
> GList *rows = gtk_tree_selection_get_selected_rows(selection,
> &model);
> GList *first = g_list_first (rows);
> g_print("Selected row is %d\n", (gint *)first->data);
>
> Select row one anbd this is the output of the above:
> selected row is: This is row 1
> Number of selected rows = 1
> Selected row is 947368
Citing http://developer.gnome.org/doc/API/2.0/gtk/GtkTreeSelection.html#gtk-tree-selection-get-selected-rows:
Returns: A GList containing a GtkTreePath for each selected row.
In other words, the list consists of GtkTreePaths, not
ints, so you print the pointer to the GtkTreePath (casted to
an int) instead of the row number. The reference also
describes how to free the returned list properly.
Yeti
--
http://gwyddion.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]