[Gtk-sharp-list] Problem with TreeView on Win32

Ivan Dubrov WFrag@yandex.ru
Thu, 08 Jan 2004 09:50:55 +0600


Hi, All!

  Just another question regarding GTK#. I've tried TreeView - basicly it 
works, but when I use TreeCellDataFunc it crashes with 
NullReferenceException at Gtk.Widget.gtk_widget_show_all. Here the code:

namespace GtkSamples
{
    using System;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Reflection;
    using Gtk;
    using GtkSharp;

    public class TreeViewDemo
    {
        private static void CellData (Gtk.TreeViewColumn tree_column, 
Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter)
        {
            ((CellRendererText) cell).Text = "a";
        }
       
        public static void Main (string[] args)
        {
            Application.Init ();

            TreeStore store = new TreeStore(typeof(string));
            string[] combs = {"foo", "bar", "baz", "quux"};
            foreach (string a in combs)
                store.AppendValues (a);

            Window win = new Window ("TreeView demo");
            TreeView tv = new TreeView (store);
            tv.HeadersVisible = true;

            tv.AppendColumn ("One", new CellRendererText (), new 
TreeCellDataFunc (CellData));
// with string below everything is OK, but with string above application 
crashes with an exception
//            tv.AppendColumn ("One", new CellRendererText (), "text", 0);
            win.Add(tv);
            win.ShowAll ();
            Application.Run ();
        }
    }
}

Anybody knows what's the problem? Tested on Windows.