[Gtk-sharp-list] TreeView & Glade on win32 via .NET

Gonzalo Paniagua Javier gonzalo@ximian.com
20 Apr 2003 21:19:22 +0200


El dom, 20 de 04 de 2003 a las 21:02, McP escribió:
> Before answer, I have a question about getting the cursor in a TreeView.
> 
> In gtk+ we have in GtkTreeView this
> (http://developer.gnome.org/doc/API/2.2/gtk/GtkTreeView.html#gtk-tree-view-get-cursor):
> void gtk_tree_view_get_cursor(
> 	GtkTreeView *tree_view,
> 	GtkTreePath **path,
> 	GtkTreeViewColumn **focus_column);
> Fills in path and focus_column with the current path and focus column.
> If the cursor isn't currently set, then *path will be NULL. 
> If no column currently has focus, then *focus_column will be NULL.
> 
> In gtk# gapi traduces it with:
> public void GetCursor(Gtk.TreePath path, 
> 	Gtk.TreeViewColumn focus_column) 
> {
>    gtk_tree_view_get_cursor(Handle,path.Handle,focus_column.Handle);
> }
> 
> Is this the correct traduction for pointers to pointers (**)?
> With this code I have to create new TreePath and a new TreeViewColumn,
> which will point to another path and column after the funcion (see
> code).
> Why don't use references ?

It should be (out TreePath path, out TreeViewColumn column). if you
want, you can fix it in sources/Gtk.metadata and api/gtk-sharp.xml and
send a patch.

> 
> If I use GetCursor I have a System.NullReferenceException:
> System.NullReferenceException: A null value was found where an object
> instance was required
> in (unmanaged) 06 Gtk.ListStore:gtk_tree_model_get_iter
> (intptr,Gtk.TreeIter&,intptr)
> in <0x00004> 06 Gtk.ListStore:gtk_tree_model_get_iter
> (intptr,Gtk.TreeIter&,intptr)
> in <0x00042> 00 Gtk.ListStore:GetIter (Gtk.TreeIter&,Gtk.TreePath)
> in <0x0012c> 00 .MultimediaTagger:TabPressed
> (object,GtkSharp.KeyPressEventArgs)
> 
> This is the code
> void TabPressed(object o, KeyPressEventArgs args)
> {
> 	Gdk.EventKey key = args.Event;
> 	if(key.keyval == ((uint)Gdk.Key.Tab))
> 	{
> 		TreeIter iter;
> 		TreeView tree = (TreeView) o;
> 		// I have to create new objects
> 		TreePath path = new TreePath();
> 		TreeViewColumn col = new TreeViewColumn();
> 
> 		tree.GetCursor(path,col);
> 		try{
> 			tree.Model.GetIter(out iter,path);
> 		}
> 		catch(System.Exception e)
> 		{
> 			Console.WriteLine(e);
> 			return;
> 		}
> 		......
> 	
> 	--------------------- THE ANSWER ----------------------
> 
> If you want to have two columns (one with a pixbuf and a label and the
> other with a label), you have to do this:
> 
> note: columnId.Icon == ColumnId.Name
> 
> //Don't use Pixbuf type !!!
> store = new TreeStore((int)TypeFundamentals.TypeString,
> 	(int)TypeFundamentals.TypeString);
[...]

This is not new. I do it that way in nunit-gtk ;-).

-Gonzalo