wxTreeCtrl question. 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.
Post Reply
GeertVc
Super wx Problem Solver
Super wx Problem Solver
Posts: 273
Joined: Fri Sep 09, 2005 4:42 pm
Location: Belgium

wxTreeCtrl question.

Post by GeertVc » Sat Sep 24, 2005 9:30 am

Hi,

I'm trying to build up a treectrl and I want to have multiple roots. See drawing below. Is this possible?

Code: Select all

+Root1-+-child1-+-child1-+-child1-+-leaf1
       |        |        |        |
       |        |        |        +-leaf2
       |        |        |        |
       |        |        |        +-leaf3
       |        |        |
       |        |        +-child2-+-leaf1
       |        |                 |
       |        |                 +-leaf2
       |        |
       |        +-child2-+-child1-+-leaf1
       |                 |        |
       |                 |        +-leaf2
       |                 |                
       |                 +-child2-+-leaf1
       |                          |
       |                          +-leaf2
       |
       +-child2-+-child1-+-child1-+-leaf1
                |        |        |
                |        |        +-leaf2
                |        |        |
                |        |        +-leaf3
                |        |
                |        +-child2-+-leaf1
                |                 |
                |                 +-leaf2
                |
                +-child2-+-child1-+-leaf1
                         |        |
                         |        +-leaf2
                         |                
                         +-child2-+-leaf1
                                  |
                                  +-leaf2

+Root2-+-child1-+-child1-+-child1-+-leaf1
       |        |        |        |
       |        |        |        +-leaf2
       |        |        |        |
       |        |        |        +-leaf3
       |        |        |
       |        |        +-child2-+-leaf1
       |        |                 |
       |        |                 +-leaf2
       |        |
       |        +-child2-+-child1-+-leaf1
       |                 |        |
       |                 |        +-leaf2
       |                 |                
       |                 +-child2-+-leaf1
       |                          |
       |                          +-leaf2
       |
       +-child2-+-child1-+-child1-+-leaf1
                |        |        |
                |        |        +-leaf2
                |        |        |
                |        |        +-leaf3
                |        |
                |        +-child2-+-leaf1
                |                 |
                |                 +-leaf2
                |
                +-child2-+-child1-+-leaf1
                         |        |
                         |        +-leaf2
                         |                
                         +-child2-+-leaf1
                                  |
                                  +-leaf2
I'm trying to do this:

Code: Select all

    trectlComponentOverview->AddRoot( "Root1" );
    trectlComponentOverview->AddRoot( "Root2" );
to have a treectrl view with two starting roots, but I only see Root1, I don't see Root2

Best rgds,

--Geert
In commemoration of my beloved Mother...

Vaulter
Earned a small fee
Earned a small fee
Posts: 19
Joined: Thu Jun 30, 2005 7:49 am
Location: Russia
Contact:

Post by Vaulter » Sat Sep 24, 2005 9:51 am

create treevtrl with wxTR_HIDE_ROOT
Use this style to suppress the display of the root node, effectively causing the first-level nodes to appear as a series of root nodes.

GeertVc
Super wx Problem Solver
Super wx Problem Solver
Posts: 273
Joined: Fri Sep 09, 2005 4:42 pm
Location: Belgium

Post by GeertVc » Sat Sep 24, 2005 10:39 am

Vaulter wrote:create treevtrl with wxTR_HIDE_ROOT
Use this style to suppress the display of the root node, effectively causing the first-level nodes to appear as a series of root nodes.
Doesn't seem to work.

This is the instance creation:

Code: Select all

	trectlComponentOverview = new wxTreeCtrl(this, ID_TRECTLCOMPONENTOVERVIEW, wxPoint(415,215), wxSize(231,252), wxSUNKEN_BORDER | wxVSCROLL | wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT | wxTR_HIDE_ROOT);
This is the code I'm using to load the roots of the tree:

Code: Select all

    for ( size_t Counter = 0; Counter < NrOfLines; Counter++ )
    {
        ActualString = arraystring.Item( Counter );
        
        EndPos = ActualString.Find( "\" ); //Found first part, which is the root
        ActualString = ActualString.Mid( 0, EndPos );

        if ( 0 != PreviousString.Cmp( ActualString ) )
        {
            TItemIdArray.Add( new wxTreeItemId );
	    wxTreeItemId TItemId = TItemIdArray.Item( Counter );
            LOGTEXT( _T( "New subroot: " + ActualString + "\n" ) );
            PreviousString = ActualString;
            TItemId = trectlComponentOverview->AddRoot( ActualString );
        }
    } 
With this code, I'm expecting to see 5 'starting roots', but I see non until I remove again the wxTR_HIDE_ROOT style.

Am I missing something? Any idea?

Best rgds,

--Geert
In commemoration of my beloved Mother...

benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte » Sat Sep 24, 2005 10:52 am

There cannot be several roots.

Add your 5 nodes as children of the root and hide it with wxTR_HIDE_ROOT .

GeertVc
Super wx Problem Solver
Super wx Problem Solver
Posts: 273
Joined: Fri Sep 09, 2005 4:42 pm
Location: Belgium

Post by GeertVc » Sat Sep 24, 2005 11:00 am

benedicte wrote:There cannot be several roots.

Add your 5 nodes as children of the root and hide it with wxTR_HIDE_ROOT .
Yep!

It's unbelievable how so-called difficult problems most of the time have such easy, logically and straightforward solutions! But you have to know them, of course...

Thanks very much!

@Vaulter: sorry for the misunderstanding, but you gave the correct hint. It was me who didn't completely got it... :-(

Best rgds,

--Geert
In commemoration of my beloved Mother...

GeertVc
Super wx Problem Solver
Super wx Problem Solver
Posts: 273
Joined: Fri Sep 09, 2005 4:42 pm
Location: Belgium

Post by GeertVc » Sat Sep 24, 2005 12:22 pm

benedicte wrote:There cannot be several roots.

Add your 5 nodes as children of the root and hide it with wxTR_HIDE_ROOT .
Does anyone know which is the best method to save the wxTreeItemId's returned by the function call

Code: Select all

trectlComponentOverview->AppendItem( m_RootId, ActualString );
when creating multiple children? Using a wxArray? Something else?
Further on, I want to be able to retrieve which wxTreeItemId's have been assigned.

In my case, those children act as different roots, since I'm using the wxTR_HIDE_ROOT style.

The amount of 'root children' is not known at compile time, so I need a dynamic way of working...

Best rgds,

--Geert
In commemoration of my beloved Mother...

Post Reply