0
votes

I want to select a GtkTreeview row by specifying an ID with the C GTK+ version.

I found this function:

gtk_tree_selection_select_iter (GtkTreeSelection *selection, GtkTreeIter *iter);

Unfortunately, I don't know how to get GtkTreeSelection and GtkTreeIter items from a specific ID.

1

1 Answers

1
votes

We can use gtk_tree_view_get_selection() to get GtkTreeSelection.

Use gtk_tree_model_get_iter() to get GtkTreeIter, which needs a GtkTreePath. And a GtkTreePath can be created by calling gtk_tree_path_new_from_string() or gtk_tree_path_new_from_indices(). Alternatively, if you already have a GtkTreePath, but want to move to next/previous iterator, you can call gtk_tree_path_next() or gtk_tree_path_prev().

I've written a demo app for you. TreeSelection is changed when you press the spin button. Full code can be found here.

Below is a screenshot:

screenshot