[Gtk-sharp-list] Tree selection

George Farris george@gmsys.com
18 Feb 2003 19:19:56 -0800


OK how the heck do I get a selected row of text out of the TreeView
widget?

This widget is seriously complex and without good documentation it's
extremely difficult.  Some of the gtk functions don't even map to the
gtk# class functions.

I think who ever created the TreeView was on some bad drugs:-)

A lot of other stuff I've figured out but if there is one widget that
could use with a nice straight forward howto it's this thing.

Any help appreciated.

I've attach a class I use to setup columns and put text in by passing it
a TreeView and ListStore.  It works but can anyone point out anything
seriously wrong with it?  I'd like to add getting a selection.


public class G_ListView
{	
	Gtk.ListStore store;
	Gtk.TreeView tree;
	Gtk.TreeViewColumn column;
	Gtk.CellRenderer text;
	Gtk.TreeIter iter;
		
	public G_ListView (Gtk.TreeView tr, Gtk.ListStore st)
	{
		store = st;
		tree = tr;
		iter = new Gtk.TreeIter();
	}
		
	public void AddColumnTitle (string title, int sortid, int col)
	{
		column = new TreeViewColumn ();
		text = new CellRendererText ();
		column.Title = title;
		column.SortColumnId = sortid;
		column.Sizing = TreeViewColumnSizing.Autosize;
		column.PackStart (text, true);
		column.AddAttribute (text, "text", col);
		tree.AppendColumn(column);
	}

	public void AddTextToRow (params string[] args)
	{
		int ctr;
		
		store.Append (out iter);
		for (ctr = 0; ctr < args.Length; ctr++)
		{
			GLib.Value value = new GLib.Value(args[ctr]);
			store.SetValue (iter, ctr, value);
		}
		tree.Model = store;
	}
}
-- 
George Farris <george@gmsys.com>