Gtk# 和 TreeView : how to get "selected" item?

标签 gtk gtk#

我无法理解在 GTK# 中如何获取树 View 的选定项。
我的代码示例:
在这里,我在 tvStock 中加载数据

        Gtk.TreeViewColumn marketCol = new Gtk.TreeViewColumn ();
            marketCol.Title = "Market";

            tvstock.AppendColumn(marketCol);

            Gtk.TreeIter iter = stockListStore.AppendValues ("Dax30");      

            stockListStore.AppendValues(iter, "Adidas");
            stockListStore.AppendValues(iter, "Commerzbank");

            iter = stockListStore.AppendValues ("Cac40");       
            stockListStore.AppendValues(iter, "Bnp Paribas");
            stockListStore.AppendValues(iter, "Veolia");

            iter = stockListStore.AppendValues ("FtseMib");     
            stockListStore.AppendValues(iter, "Fiat");
            stockListStore.AppendValues(iter, "Unicredit");

            tvstock.Model = stockListStore;

            // Create the text cell that will display the artist name
            Gtk.CellRendererText marketNameCell = new Gtk.CellRendererText ();
            // Add the cell to the column
            marketCol.PackStart (marketNameCell, true);     

            // Tell the Cell Renderers which items in the model to display
            marketCol.AddAttribute (marketNameCell, "text", 0);         

在我的 OnTvstockRowActivated 上,如何获得选定的行?
谢谢

最佳答案

您在 args 中有行的路径,您可以从中生成一个迭代器。

protected virtual void OnTvstockRowActivated (object o, Gtk.RowActivatedArgs args)
{
    var model = tvstock.Model;
    TreeIter iter;
    model.GetIter (out iter, args.Path);
    var value = model.GetValue (iter, 0);
    Console.WriteLine (value);
}

关于Gtk# 和 TreeView : how to get "selected" item?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4217861/

相关文章:

c# - 在 c# 中线程函数不起作用

treeview - Gtk.TreeView 无法添加自定义渲染器,断言 'gtk_cell_area_has_renderer (area, renderer)' 失败

GTK 窗口调整大小禁用而不返回默认值

c++ - 可以将Gtk +应用程序编译为在Gtk 2和3上运行

c++ - 是否可以使用 gtkmm 定义 GTK+ 类型?

c# - textEntry.Text 输出是 Gtk.Entry (单声道)

java - 如何更改 Swing GTK LookAndFeel 中的默认字体大小?

c# - 无法使用 MS .NET 运行时运行 GTK# 应用程序,只能使用 Mono 运行

c# - 如何在 TextView 控件中剪切、复制、粘贴和全选?

c# - 在 Win7 32 位上使用 Gtk# 进行国际化