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

Peter Williams peter@newton.cx
Sun, 17 Oct 2004 16:53:57 -0400

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?


Peter Williams                          peter@newton.cx

"[Ninjas] are cool; and by cool, I mean totally sweet."
                              -- REAL Ultimate Power