Collapsable wxGrid

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Nunki
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 221
Joined: Fri Sep 14, 2012 8:26 am
Location: Kontich, Belgium
Contact:

Collapsable wxGrid

Post by Nunki » Tue Jan 16, 2018 10:03 pm

Hi guys,

I'm looking for a way to have a wxGrid that has collapsable rows. Meaning a row may have one or more rows attached. and by means of a mouseclick these rows appear or disappear (expand/collapse). How would you achieve this. Are there extended wxGrid implementations that do this ?

regards,
Nunki

User avatar
doublemax
Moderator
Moderator
Posts: 15065
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Collapsable wxGrid

Post by doublemax » Tue Jan 16, 2018 10:51 pm

wxGrid doesn't support this and i can't think of an easy way to fake it. Look into wxDataViewCtrl.
Use the source, Luke!

iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 273
Joined: Tue Mar 19, 2013 8:52 pm

Re: Collapsable wxGrid

Post by iwbnwif » Wed Jan 17, 2018 11:14 am

Hi Nunki,

I also wanted to do something like this a couple of years ago. I searched for a suitable control but was not successful.

The problem with wxDataViewCtrl is that all the collapsing is done in the first column. We wanted the top level branches in the first column, second level branches in the second column, third level branches in the third column etc. etc.

In the end the project got dropped, but the approach we decided on was to create a custom control based on the generic version of wxDataViewCtrl code and using the underlying data wxDataViewTreeStore. Our attempts only got as far as a very quick mock-up with minimal functionality, but actually it wasn't as hard as I had feared, because the generic control drawing is fairly straightforward.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.

Nunki
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 221
Joined: Fri Sep 14, 2012 8:26 am
Location: Kontich, Belgium
Contact:

Re: Collapsable wxGrid

Post by Nunki » Wed Jan 17, 2018 9:28 pm

Hi iwbnwif,

I've been thinking about this and my idea is that I probably will have to create a class based upon wxGrid to extend it. I tested something else first, I added a column containing the hashkey of the database rows displayed in wxGrid and then hid it with hGrid->HideCol(nLastCol); The effect was that you could not see the column, but it was there and you could access the content of it. Now I was thinking of a grid with the first colum, or the row labels containing a triangular image or + or - image to control whether rows that contain under a master row are shown or hidden. For there is a method in wxGrid hGrid->HideRow(nRow); and hGrid->ShowRow(); That would probably give the effect I'm after. I'll keep on experimenting and will keep you in the loop, though I'm always open for suggestions or remarks.

Regards,
Nunki

Post Reply