[Gtk-sharp-list] Can I group items in TreeView without rebuilding model?

László Monda mondalaci at gmail.com
Fri Nov 11 07:54:23 EST 2005

Hey Michael,

On Sun, 2005-11-06 at 00:54 +0000, Michael Hutchinson wrote:
> I have a TreeView that is displaying a lisi, and I'm looking for a way
> to group all items with the same value in a certain column by making
> them children of a 'category' node, and I can do this using a
> TreeStore. I will need to do the same thing to a tree at some point,
> but not grouping the children of the top level.
> However, I also need to be able to switch between grouped and
> ungrouped views.The easy way seems to be to rebuild/rearrange the
> model when the 'mode' changes, though I'm unhappy with this as it
> breaks the model/view separation and could cause a performance hit. I
> see two ways to do this, using either a TreeStore, which as far as I
> can see doesn't allow reparenting rows, or a NodeStore - reparenting
> rows is possible, but I /think/ the model involves more interop. Which
> is likely to be faster? Is there any better way to do what I'm trying
> to do?
> Another route I've considered is writing a TreeModel that will group
> rows in a child TreeModel by a given column, like the filtering and
> sorting TreeModels. This would be more generally useful, and keeps the
> model separation intact, but are there any problems I'd need to be
> aware of when writing a managed TreeModel? Would it be best to sit it
> on top of the filtering TreeModel, as presumably this already does
> optimised sorting? And would there be any interest in using such a
> TreeModel?

Well, there are two options that come to my mind:

1) I think writing your own TreeModel would be the most elegant
solution, but this is an advanced topic, no questions and the details
could be evil, which I'm not aware of specifically.

2) However creating your own stores per views and maintaining them is
probably easier to do, but less elegant and the code is harder to
maintain in the long run.

I'd try 1) and if it doesn't work out, I'd move to 2).

This is all general stuff, of course, but I hope that it helps.


    Blog: http://monda.hu/~laci/blog
    Home: http://mondalaci.objectis.net

More information about the Gtk-sharp-list mailing list