[Gtk-sharp-list] How to Get Row Values from a TreeView

Marc Glenn mjamon at ntsp.nec.co.jp
Thu Feb 14 19:56:06 EST 2008


I think this would help.
Thank you very much.

Philip Van Hoof wrote:
> On Thu, 2008-02-14 at 15:27 +0800, Marc Glenn wrote:
>   
>> Hello everyone,
>>
>>      Does anyone know how to retrieve values currently displayed on a 
>> TreeView widget?
>>
>>      Suppose a row entry from the TreeView was clicked, how can the the 
>> data in the row be retrieved?
>>
>>      I checked the Mono Documentation but I can't find a method to do this.
>>     
>
> There are a few ways, but this is one possibility:
>
> treeview.Selection.Changed += OnSelectionChanged;
>
> private void OnSelectionChanged; (object o, EventArgs args)
> {
> 	Gtk.TreeSelection selection = o as Gtk.TreeSelection;
> 	YourColumn'sType data;
> 	Gtk.TreeModel model;
> 	Gtk.TreeIter iter;
>
> 	if (selection.GetSelected (out model, out iter)) {
> 		int column = YourColumnNumber;
> 		GLib.Value val = GLib.Value.Empty;
> 		model.GetValue (iter, column, ref val);
> 		data = (YourColumn'sType) val.Val;
> 		val.Dispose ();
> 	}
> }
>
> Advise: check out the Model View Controller pattern in detail.
>
> Change "YourColumn'sType" into "string" in case the data is a string.
>
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20080215/7e7fa997/attachment.html 


More information about the Gtk-sharp-list mailing list