[Solved] GtkTreeView set selection to specific row


You don’t need to use a GtkTreeIter for this, the GtkTreePath API is enough. You’re throwing your path away before using it, which creates problems.

Here’s how to do it:

GtkTreePath *path = gtk_tree_path_new_from_indices(3, -1);
gtk_tree_selection_select_path(treeview_selection, path);
gtk_tree_path_free(path);

UPDATE: I rewrote the code completely to drop use of GtkTreeIter, I originally thought that you wanted a solution using an iter since that was what you were trying to do.

If you just want to do a selection (and don’t, for instance, need a GtKTreeIter for something else) the above is the simplest way using just a GtkTreePath.

Take care not do destroy the path before using it in the select-call, of course.

3

solved GtkTreeView set selection to specific row