Gtk#和treeview:如何获得"选中"项目?

sti*_*ghy 3 gtk gtk#

我无法理解GTK#如何获取树视图的选定项目.我的代码示例:在这里,我在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);         
Run Code Online (Sandbox Code Playgroud)

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

sil*_*ilk 5

你有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);
}
Run Code Online (Sandbox Code Playgroud)