[Gtk-sharp-list] TreeCellDataFunc problem

Freon Freon <freongrr@gmail.com>
Mon, 1 Nov 2004 15:09:57 +0100


Hi,

I've been trying to get custom formatting in a TreeView using
TreeCellDataFunc, but to no avail.
Everything works fine when defining the tree or when the delegate
testDataFunc() is executed, but it crashes on ShowAll() with the
following error message:

Error :    at Gtk.Widget.gtk_widget_show_all(IntPtr raw)
   at Gtk.Widget.ShowAll()
   at TreeViewTest.Main(String[] args) in
c:\mono\prj\bugtreeview\main.cs:line 35

(<unknown>:3692): Gtk-CRITICAL **: file gtkmain.c: line 1187
(gtk_main_quit): assertion `main_loops != NULL' failed

Here is the test file I use:
(btw, I'm running WindowsXP with mono 1.0.2)

-----------------------------------------------------------

using System;
using System.Collections;
using Gtk;

public class TreeViewTest
{
    public static void Main(string[] args)
    {
        try 
        {
            Application.Init();

            Window win = new Window("TreeView Test");
            win.DeleteEvent += new DeleteEventHandler(OnWindowDeleteEvent);
            win.SetDefaultSize(400,250);

            ScrolledWindow sw = new ScrolledWindow();
            win.Add(sw);

            TreeStore store = new TreeStore( typeof (string) );

            for (int i=0; i < 5; i++) 
            {
                TreeIter iter = store.AppendValues("Line " + i);
            }

            TreeView tv = new TreeView();
            tv.Model = store;
            tv.HeadersVisible = true;

            tv.AppendColumn("Test", new CellRendererText(), new
TreeCellDataFunc(testDataFunc) );

            sw.Add(tv);
            sw.Show();
            win.ShowAll();
            Application.Run();
        } 
        catch(Exception e)
        {
            Console.WriteLine( "Error : " + e.StackTrace );
            Application.Quit();
        }
    }

    private static void testDataFunc (
        TreeViewColumn column,
        CellRenderer renderer,
        TreeModel model,
        TreeIter iter)
    {
        try
        {
            string text = model.GetValue(iter, 0) as string;
            (renderer as CellRendererText).Text = text.ToUpper();
        }
        catch (Exception e)
        {
            Console.WriteLine( "error : " + e.ToString() );
        }
    }

    public static void OnWindowDeleteEvent(object o, DeleteEventArgs args) 
    {
        Application.Quit();
        args.RetVal = true;
    }
}

-----------------------

Thanks in advance :)