[Gtk-sharp-list] Dynamically populating a TreeStore

Jonathan Pryor jonpryor@vt.edu
Tue, 17 Aug 2004 20:15:58 -0400


On Tue, 2004-08-17 at 07:38, Chris Ridd wrote:
<snip/>
> > You can also look at Type Reflector (Mono CVS module: type-reflector) in
> > displayers/gtk/GtkTypeDisplayer.cs.  Look at the TreeCell class and the
> > OnRenderCellText() function.
> 
> Ah, very useful. You seem to be adding parent entries into your TreeStore
> with dummy child entries and when the row is expanded you remove the dummy
> and add real children.

Correct.

> Presumably the dummy entry's there to fool the view into displaying the
> twisty triangle?

Also correct.

> That would probably *nearly* work for me, except that my nodes might not
> have children when they're expanded, but I don't really want to lose the
> twisty in case children are added later on.

Simple solution: don't remove the "dummy" children. :-)

Of course, the problem with that is then people will expand your row and
see your dummy children, which probably isn't desirable.

Solution: capture the RowExpanded event (as I did), and if you didn't
add any children, call Gtk.TreeView.CollapseRow() to explicitly collapse
the row.  (In other words, do the opposite of what I do -- CollapseRow()
instead of ExpandRow().)  This should keep the arrows present while
preventing the user from seeing your dummy nodes.

Or, figure out how to display the disclosure triangles without having
any children present.  I failed in that task, hence my use of "dummy"
children.

 - Jon