[Gtk-sharp-list] Re: Getting selection for a NodeStore

Ecmel Ercan ecmel@ercansoy.com
Wed, 28 Jan 2004 02:32:08 +0200

I have a workaround:

First some native declarations:

    static extern bool gtk_tree_selection_get_selected(IntPtr raw, out IntPtr model, out Gtk.TreeIter iter);

    public static bool GetSelected(TreeSelection selection, out Gtk.TreeIter iter)
        IntPtr model_handle;
        bool raw_ret = gtk_tree_selection_get_selected(selection.Handle, out model_handle, out iter);
        bool ret = raw_ret;
        return ret;

    static extern IntPtr gtk_tree_model_get_path(IntPtr raw, ref Gtk.TreeIter iter);

    public static Gtk.TreePath GetPath(NodeStore store, Gtk.TreeIter iter) 
        IntPtr raw_ret = gtk_tree_model_get_path(store.Handle, ref iter);
        Gtk.TreePath ret = new Gtk.TreePath(raw_ret);
        if (ret == null)
            ret = new Gtk.TreePath(raw_ret);
        return ret;

To get the selected node:

        TreeIter iter;
        GetSelected (view.Selection, out iter);

        TreePath path = GetPath (store, iter);
        ITreeNode node = store.GetNode (path);

        Console.WriteLine (path.ToString ());

This works for me.