wxDataViewCtrl how to Hide the RootItem Topic is solved

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.
Ellan
Experienced Solver
Experienced Solver
Posts: 57
Joined: Mon May 15, 2017 10:11 am

wxDataViewCtrl how to Hide the RootItem

Post by Ellan »

Hi,
I don't want to show the contents of rootitem, how do I hide it.
Thanks

Best Regards

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

Re: wxDataViewCtrl how to Hide the RootItem

Post by doublemax »

AFAIK wxDataViewCtrl doesn't have a root item as it's designed for list based and tree based data.

If the data you want to display has a root item, just irgnore it and start filling the wxDVC with the first level of children.
Use the source, Luke!
Ellan
Experienced Solver
Experienced Solver
Posts: 57
Joined: Mon May 15, 2017 10:11 am

Re: wxDataViewCtrl how to Hide the RootItem

Post by Ellan »

doublemax wrote:AFAIK wxDataViewCtrl doesn't have a root item as it's designed for list based and tree based data.

If the data you want to display has a root item, just irgnore it and start filling the wxDVC with the first level of children.
Is it implemented in the renderer?
wxDVC specifies the custom wxDataViewModel, and the wxDataVeiwRanderer is also customizable, which means that I now need to ignore first level children in the Render () function of my custom renderer?
Thanks

Best Regards

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

Re: wxDataViewCtrl how to Hide the RootItem

Post by doublemax »

No. What i meant was that you should interpret the data as if it didn't have a root item.
Use the source, Luke!
Ellan
Experienced Solver
Experienced Solver
Posts: 57
Joined: Mon May 15, 2017 10:11 am

Re: wxDataViewCtrl how to Hide the RootItem

Post by Ellan »

doublemax wrote:No. What i meant was that you should interpret the data as if it didn't have a root item.
Thank you very much for your inspiration,the data really has no root, and the only real root is NULL
Thanks

Best Regards

Ellan
Anil8753
Experienced Solver
Experienced Solver
Posts: 93
Joined: Sat Jan 16, 2016 5:57 am
Location: India

Re: wxDataViewCtrl how to Hide the RootItem

Post by Anil8753 »

It is possible, make the root item null. Find the wxDataViewCtrl sample and check the list view implementation of wxDataViewCtrl.

https://github.com/wxWidgets/wxWidgets/ ... s/dataview
rocvan
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sat May 14, 2022 6:42 am

Re: wxDataViewCtrl how to Hide the RootItem

Post by rocvan »

doublemax wrote: Thu Aug 17, 2017 8:30 am No. What i meant was that you should interpret the data as if it didn't have a root item.
Hi,
I am studying the dataview sample, and I changed the code to show only the data tree and list in single tab. The diagram as follow:
dataview sample
dataview sample
sample_dataview_00100.png (15.98 KiB) Viewed 3882 times
Is it possible to doing this kind of tree without root?


I have tried to revise the sample code, replace the m_pop by m_root. The result is "Classical music" under "Pop music", how to make all item in parallel?

Thanks again.
Last edited by rocvan on Wed Jun 15, 2022 9:33 am, edited 3 times in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewCtrl how to Hide the RootItem

Post by doublemax »

rocvan wrote: Thu Jun 02, 2022 9:28 am I have tried to revise the sample code, replace the m_pop by m_root. The result is "Classical music" under "Pop music", how to make all item in parallel?
I don't understand what you mean with all "all item(s) in parallel".
Use the source, Luke!
rocvan
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sat May 14, 2022 6:42 am

Re: wxDataViewCtrl how to Hide the RootItem

Post by rocvan »

doublemax wrote: Thu Jun 02, 2022 12:01 pm
rocvan wrote: Thu Jun 02, 2022 9:28 am I have tried to revise the sample code, replace the m_pop by m_root. The result is "Classical music" under "Pop music", how to make all item in parallel?
I don't understand what you mean with all "all item(s) in parallel".
I want to the result as follow:
simple data view
simple data view
sample_dataview_00200.png (6.81 KiB) Viewed 3653 times
+ "Pop music"
  • music 1
  • music 2
+ "Classical music"
  • music 3
  • music 4
The "Pop music" and "Classical music" align at the left most, but the root "My Music" is removed. Maybe it call vertical alignment?

Thanks
Last edited by rocvan on Tue Jul 19, 2022 3:48 pm, edited 2 times in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewCtrl how to Hide the RootItem

Post by doublemax »

"MyMusicTreeModel" needs to be modified for this.

Code: Select all

unsigned int MyMusicTreeModel::GetChildren( const wxDataViewItem &parent,
                                            wxDataViewItemArray &array ) const
{
    MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) parent.GetID();
    if (!node)
    {
        return GetChildren( wxDataViewItem(m_root), array );  // new
        // array.Add( wxDataViewItem( (void*) m_root ) );
        // return 1;
    }
Use the source, Luke!
rocvan
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sat May 14, 2022 6:42 am

Re: wxDataViewCtrl how to Hide the RootItem

Post by rocvan »

doublemax wrote: Thu Jun 02, 2022 2:32 pm "MyMusicTreeModel" needs to be modified for this.
Bravo! It works.
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

Re: wxDataViewCtrl how to Hide the RootItem

Post by ollydbg23 »

Hello, I'm also a beginner of using wxDataViewCtrl, and I'm try the way doublemax suggest.

I mean I would like to show only the tree node "Pop music" and "Classical music", but NOT the "root" (My Music) node in the dataview sample.

but I see a similar issue reported by another guy in the stackoverflow site, see here:

Add/Remove node to wxDataViewCtrl

There are two answers there. One is the OP's answer, but in his answer, there are many "Cleared()" function call needed. I think that is not necessary.

Another answer is from the VZ(wx developer), but I'm not sure how to solve the issue.

In-fact, I see few resource of the wxDataViewCtrl, I still need some help, thanks.
Last edited by ollydbg23 on Sun Sep 10, 2023 9:06 am, edited 1 time in total.
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

Re: wxDataViewCtrl how to Hide the RootItem

Post by ollydbg23 »

doublemax wrote: Thu Jun 02, 2022 2:32 pm "MyMusicTreeModel" needs to be modified for this.

Code: Select all

unsigned int MyMusicTreeModel::GetChildren( const wxDataViewItem &parent,
                                            wxDataViewItemArray &array ) const
{
    MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) parent.GetID();
    if (!node)
    {
        return GetChildren( wxDataViewItem(m_root), array );  // new
        // array.Add( wxDataViewItem( (void*) m_root ) );
        // return 1;
    }

Hi, doublemax, with your suggest changes, I see that "My Music" node is not shown, but this change cause many other issue, for example, with this change, when you click on the "Add Mozart" button, nothing happens.
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: wxDataViewCtrl how to Hide the RootItem

Post by doublemax@work »

That was just an quick-and-dirty patch to see how it works in principle. For a "real" solution, you need to make significant changes to the model. Basically you'd have to check all occurencies of "m_root" and handle each case indiviually.
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

Re: wxDataViewCtrl how to Hide the RootItem

Post by ollydbg23 »

doublemax@work wrote: Mon Jul 10, 2023 9:13 am That was just an quick-and-dirty patch to see how it works in principle. For a "real" solution, you need to make significant changes to the model. Basically you'd have to check all occurencies of "m_root" and handle each case indiviually.
OK, thanks for the response, let me check all the "m_root" occurrences, and see whether I can fix this issue.
Post Reply