GtkTreeView将选择设置为特定行 [英] GtkTreeView set selection to specific row

查看:108
本文介绍了GtkTreeView将选择设置为特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 GtkTreeSelection 设置为特定行,设置为行号 3 ?

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

我可以将选择项设置为 GtkTreeIter ,但是如何将 iter 设置为行号 3 ?

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

我没有在Google搜索中找到任何有用的东西,所以我还没有尝试任何东西,因为我不知道什么.

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!

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);

->不工作

推荐答案

您无需为此

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.

方法如下:

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

更新:我完全重写了代码以删除对 GtkTreeIter 的使用,我本来以为您想要使用iter的解决方案,因为那是您要尝试做的事情

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.

如果您只是想进行选择(例如,不需要 GtKTreeIter 来进行其他操作),则上述方法是仅使用 GtkTreePath 的最简单方法>.

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.

这篇关于GtkTreeView将选择设置为特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆