[Gtk-sharp-list] TreeView Selection

John Luke jluke@users.sourceforge.net
Wed, 07 Apr 2004 00:10:02 -0400

On Tue, 2004-04-06 at 00:18 -0400, Met wrote:
> >From a curser changed event, how do I get the selected row?  I'd imagine
> I would get an index which would let me search through the
> TreeView.Model, but I cannot find examples, and the generated code is
> driving me crazy.
> Thanks in advance,
something like this:
TreeView tv = new TreeView ();
tv.Selection.Changed += new EventHandler (OnSelectionChanged);

void OnSelectionChanged (object o, EventArgs args)
	TreeModel model;
	TreeIter iter;
	string selected = "no selection";

	// you get the iter and the model if something is selected
	if (tv.Selection.GetSelected (out model, out iter)
		selected = (string) model.GetValue (iter, column);

	Console.WriteLine (selected);