I have a tree view. In my program I want to highlight (select/set focus)
one row of the tree view. That highlighted row should be the same as if
the user had clicked on that row.

Please let me know how I may set the row.

Any assistance or suggestions are much appreciated.


On Thu, 2006-08-17 at 16:40 +1000, Donald Malcolm wrote:
> How do I set a row in a tree view list to be selected in the same manner
> as if it were clicked upon?
> 
> The tree view that I am using is populated with two columns. The first
> is not visible, and the second is displayed. So the user sees a one
> column selection where they are able to select one of the rows from the
> list.
> 
> On initial display I want to be able to pre-select one of the rows, and
> present the list to the user with that pre-selected row highlighted as
> if it were click upon.
> 
> Essentially the program goes something like the following:
> 
>         gtk_list_store_append(model, iter);
>         gtk_list_store_set( model, iter, -1);
>         g_value_init(&value, G_TYPE_STRING);
>         g_value_set_string (&value,str);
>         gtk_list_store_set_value(model, iter, i, &value);
> 
>         tv = gtk_tree_view_new_with_model((GtkTreeModel*)model);
> 
>         renderer = gtk_cell_renderer_text_new();
>         gtk_tree_view_insert_column_with_attributes(
>                 GTK_TREE_VIEW(tv),
>                 -1,
>                 heading,
>                 renderer,
>                 "markup",
>                 i,
>                 NULL);
> 
>         gtk_tree_selection_select_iter(
>                 gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)),
>                 &initial_iter);
>         path_to_initial_row = (GtkTreePath *)gtk_tree_model_get_path(
>                 (GtkTreeModel*)model, &initial_iter);
> 
>         gtk_tree_view_scroll_to_cell(
>                 GTK_TREE_VIEW(tv),
>                 path_to_initial_row,
>                 NULL,   /* as we want no column move */
>                 TRUE,   /* yes use alignments */
>                 0.5,    /* align vertical to middle */
>                 0);     /* align Left Hand Side */
> 
>         gtk_tree_view_set_cursor(GTK_TREE_VIEW(tv),
>                 path_to_initial_row, NULL, FALSE);
> 
> The last statement "gtk_tree_view_set_cursor" has no effect, and is my
> best guess at getting the selected row to be highlighted. What happens
> is that the row is greyed, and I suspect that means the row is selected,
> but does not have focus. I want it to have focus, so that when the user
> presses enter, the current line is returned as the selected one.
> 
> What I need to do, is get the program to recognise an initial row, so
> that when the user does not click on anything, the initial row is
> initially displayed as having focus, and therefore is the selected row
> upon return from the window.
> 
> 
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to