C++ samples\dataview: wxDataViewTreeCtrl and AppendTextColumn(...)

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
widgetsfox
Earned a small fee
Earned a small fee
Posts: 13
Joined: Wed Sep 14, 2016 9:33 pm

C++ samples\dataview: wxDataViewTreeCtrl and AppendTextColumn(...)

Post by widgetsfox »

Hello,

that question is the same related to wxPython, see here.
I hope that the chances to get an answer is better with an C++ example.

I'm working with OS Win 7/wxWidgets v. 3.1.0. You can find that example "wxDataViewCtrl sample" in the folder samples\dataview, dataview.cpp.

It consits of an wxNotebook and four wxPanels. The last one contains an wxDataViewTreeCtrl. Code starts at line 730:

Code: Select all

   case 3:
		{
			wxASSERT(!m_ctrl[3]);
			wxDataViewTreeCtrl* tc =
				new wxDataViewTreeCtrl( parent, wxID_ANY, wxDefaultPosition,
										wxDefaultSize, style | wxDV_NO_HEADER );
			m_ctrl[3] = tc;

			wxImageList *ilist = new wxImageList( 16, 16 );
			ilist->Add( wxIcon(wx_small_xpm) );
			tc->AssignImageList( ilist );

			wxDataViewItem parent =
				tc->AppendContainer( wxDataViewItem(0), "The Root", 0 );
			tc->AppendItem( parent, "Child 1", 0 );
			tc->AppendItem( parent, "Child 2", 0 );
			tc->AppendItem( parent, "Child 3, very long, long, long, long", 0 );

			wxDataViewItem cont =
				tc->AppendContainer( parent, "Container child", 0 );
			tc->AppendItem( cont, "Child 4", 0 );
			tc->AppendItem( cont, "Child 5", 0 );

			tc->Expand(cont);
		}
		break;
How (and where, position in code) can I add columns in that wxDataViewTreeCtrl?

Code: Select all

tc->AppendTextColumn( ??? );
In dataview.h

Code: Select all

line 583:
wxDataViewColumn *AppendTextColumn( const wxString &label, unsigned int model_column,
                                    wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
                                    wxAlignment align = wxALIGN_NOT,
                                    int flags = wxDATAVIEW_COL_RESIZABLE );
line 607:
wxDataViewColumn *AppendTextColumn( const wxBitmap &label, unsigned int model_column,
                                    wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
                                    wxAlignment align = wxALIGN_NOT,
                                    int flags = wxDATAVIEW_COL_RESIZABLE );
Are the headers shown by default? Any hints are highly appreciated!


Many thanks and greetings
widgetsfox
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: C++ samples\dataview: wxDataViewTreeCtrl and AppendTextColumn(...)

Post by doublemax »

I think a wxDataViewTreeCtrl can only have one column and you need a custom model (like on the first tab of that sample) to have a combined tree- and list-control (which can have multiple columns).
Use the source, Luke!
Post Reply