[Gtk-sharp-list] Keeping track of rows in sorted lists

Todd Berman tberman@off.net
Sun, 17 Oct 2004 14:03:51 -0700

On Sun, 2004-10-17 at 16:53 -0400, Peter Williams wrote:
> Hi all,
> I'm having a problem implementing a sort TreeModel in C#. I think
> there's an API deficiency in Gtk# causing the issue, but I might just be
> missing something.
> I have a sortable GtkTreeModel with editable text cells. Each row
> corresponds to a C# 'Item' class. When a cell is edited, it gets a
> signal and a Gtk.TreePath passed to it. I was using the TreePath as a
> key into a hashtable pointing to my Item instances, but I realized that
> TreePaths change as the tree is sorted. So if the tree is sorted, I'll
> look up and edit the wrong item. Bad.
> Is there a recommended way to map from a TreePath to the Item class
> corresponding to the correct row in the tree? I haven't found any good
> examples of how to do this, in C or C#. It looks like maybe you're
> supposed to set the user_data fields of Gtk.TreeIter, but these aren't
> exposed in the Gtk# API. I see the TreeRowReference class, but that maps
> Item -> TreePath, and I need the reverse.
> Should Gtk# expose some sort of 'public object UserData' in its TreeIter
> wrapper, or is there a better way to achieve what I want?

My recommendation is to store the actual data objects inside the

you can do this like so: new TreeStore (typeof (Item));

and you can either use TreeCellDataFuncs to render, or store a string,
and then the Item.

That way when the string is sorted, your item is sorted with it.