Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I set the GtkTreeSelection to a specific row, to the row number 3?

I can set the selection to the GtkTreeIter, but how can i set the iter to the row number 3?

I didn't find anything useful at the google search, so I didn't try anything yet because I don't know what.

I hope you can help me and give me information about my questions!

EDIT:

GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
GtkTreePath *path = gtk_tree_path_new_from_indices(3, -1);
gtk_tree_model_get_iter(model, &iter, path);
gtk_tree_path_free(path);
gtk_tree_selection_select_path(treeview_selection, path);

-> Don't work

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
254 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...