[Gtk-sharp-list] Issue With TreeSelection.GetSelectRows(TreeModel) Indexer

John BouAntoun jbafactor@optusnet.com.au
Fri, 16 Jan 2004 18:49:12 +1100


--=-1wYbEqLadp8mhrb8nsQx
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi guys,

I'm having a problem using the Indexer from the ListBase Interface of
the GLib.List Object that is returned by
TreeSelection.GetSelectRows(TreeModel) when using multiple selection
mode.

Whenever I do something like this (and at least one item is selected):

GLib.List a = treeview.Selection.GetSelectRows(store);

The following works

a.Count > 0 

but this doesn't work

System.Console.WriteLine(a[0]);

I have put together a small testcase out of the Simple treeview example
in monodoc. I simply added a selection changed event that exhibits this
behaviour.

I have attached the C#. Simply do the following
mcs test.cs /r:gtk-sharp.dll /r:glib-sharp.dll

then run and select an item in the list.

You will get the following error:

        Unhandled Exception: System.NullReferenceException: A null value
        was found where an object instance was required
        in (unmanaged) (wrapper managed-to-native)
        GLib.Object:gtksharp_is_object (intptr)
        in <0x00004> (wrapper managed-to-native)
        GLib.Object:gtksharp_is_object (intptr)in <0x0000d>
        GLib.Object:IsObject (intptr)
        in <0x00121> GLib.ListBase:DataMarshal (intptr)
        in <0x0003f> GLib.ListBase:get_Item (int)
        in <0x0008f> .TreeViewSample:selectEvent
        (object,System.EventArgs)
        in <0x0006d> (wrapper delegate-invoke)
        System.MulticastDelegate:invoke_void_object_EventArgs
        (object,System.EventArgs)
        in <0x0012b> GtkSharp.voidObjectSignal:voidObjectCallback
        (intptr,int)
        in <0x00030> (wrapper native-to-managed)
        GtkSharp.voidObjectSignal:voidObjectCallback (intptr,int)
        in (unmanaged) (wrapper managed-to-native)
        Gtk.Application:gtk_main ()
        in <0x00004> (wrapper managed-to-native)
        Gtk.Application:gtk_main ()
        in <0x00007> Gtk.Application:Run ()
        in <0x0048a> .TreeViewSample:Main (string[])

I need someone to verify that this is indeed an error in gtk-sharp so
that it can be filed in bugzilla as a bug.

Thanks in advance

jba.


--=-1wYbEqLadp8mhrb8nsQx
Content-Disposition: attachment; filename=test.cs
Content-Type: text/plain; name=test.cs; charset=UTF-8
Content-Transfer-Encoding: 7bit

using System;
using Gtk;
using GtkSharp;
public class TreeViewSample 
{
	static TreeView tv;
	static TreeStore store;
	
	public static void Main (string [] args)
    { 
		Application.Init ();
		store = new TreeStore (typeof (string), typeof (string));          
		for (int i=0; i < 5; i++)          
		{               
			TreeIter iter = store.AppendValues ("Demo " + i, "Data " + i);          
		}                                  

		Window win = new Window ("TreeView List Demo");          
		win.DeleteEvent += new DeleteEventHandler (delete_cb);          
		win.SetDefaultSize (400,250);          
		ScrolledWindow sw = new ScrolledWindow ();          
		win.Add (sw);          
		tv = new TreeView ();          
		tv.Model = store;          
		tv.HeadersVisible = true;          
		tv.Selection.Mode = SelectionMode.Multiple;
		tv.AppendColumn ("Demo", new CellRendererText (), "text", 0);          
		tv.AppendColumn ("Data", new CellRendererText (), "text", 1);		                                  
		sw.Add (tv);          
		sw.Show ();          
		win.ShowAll ();         
		Application.Run ();
		
		// new line added for test case
		tv.Selection.Changed += new EventHandler(testCase);
	}

	private static void delete_cb (System.Object o, DeleteEventArgs args)     
	{          
		Application.Quit ();          
		args.RetVal = true;     
	}
	
	// new function added for testcase
	static void testCase(object sender, EventArgs e)
	{
		if (tv.Selection.CountSelectedRows() >= 1) {
			GLib.List list = tv.Selection.GetSelectedRows(store);
				System.Console.WriteLine(list.Count);
				System.Console.WriteLine("a" + list[0]);
		}
	}
}
--=-1wYbEqLadp8mhrb8nsQx--