如何将GtkTreeSelection
设置为特定行,行号3
?
我可以将选择设置为GtkTreeIter
,但如何将iter
设置为行号3
?
我在谷歌搜索中找不到任何有用的东西,所以我还没有尝试任何东西,因为我不知道是什么。
我希望你能帮助我并向我提供有关我的问题的信息!
编辑:
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);
- >不工作
答案 0 :(得分:1)
您不需要使用GtkTreeIter
,GtkTreePath
API就足够了。在使用它之前,你会抛弃你的路径,这会产生问题。
以下是如何操作:
GtkTreePath *path = gtk_tree_path_new_from_indices(3, -1);
gtk_tree_selection_select_path(treeview_selection, path);
gtk_tree_path_free(path);
UPDATE :我完全重写了代码以放弃GtkTreeIter
的使用,我原本以为你想要一个使用iter的解决方案,因为那是你想要做的。
如果你只是想做一个选择(例如,不需要GtKTreeIter
来做其他事情),上面是仅使用GtkTreePath
的最简单方法。
当然,在使用select-call之前,请注意不要破坏路径。