From WxWiki
Jump to: navigation, search
Official Classes SmallBlocks.png Archive Containers Controls Data Structures Database Date & Time Debug Device Contexts Dialogs Document & Views Drag & Drop Events Filesystem Frames Graphics Grid Cell Help HTML Logging Miscellaneous Networking Printing Sizers Streams Threading Windows

A control combining wxTreeCtrl and wxListCtrl features.

This is a multi-column tree control optionally supporting images and checkboxes for the items in the first column.

It is currently implemented using wxDataViewCtrl internally but provides a much simpler interface for the common use case it addresses. Thus, one of the design principles for this control is simplicity and intentionally doesn't provide all the features of wxDataViewCtrl. Most importantly, this class stores all its data internally and doesn't require you to define a custom model for it.

Instead, this controls works like wxTreeCtrl or non-virtual wxListCtrl and allows you to simply add items to it using wxTreeListCtrl::AppendItem() and related methods. Typically, you start by setting up the columns (you must have at least one) by calling wxTreeListCtrl::AppendColumn() and then add the items. While only the text of the first column can be specified when adding them, you can use wxTreeListCtrl::SetItemText() to set the text of the other columns.

Unlike wxTreeCtrl or wxListCtrl this control can sort its items on its own. To allow user to sort the control contents by clicking on some column you should use wxCOL_SORTABLE flag when adding that column to the control. When a column with this flag is clicked, the control resorts itself using the values in this column. By default the sort is done using alphabetical order comparison of the items text, which is not always correct (e.g. this doesn't work for the numeric columns). To change this you may use SetItemComparator() method to provide a custom comparator, i.e. simply an object that implements comparison between the two items. The treelist sample shows an example of doing this. And if you need to sort the control programmatically, you can call SetSortColumn() method.

Here are the styles supported by this control. Notice that using wxTL_USER_3STATE implies wxTL_3STATE and wxTL_3STATE in turn implies wxTL_CHECKBOX.

WARNING: since version 2.9, wxWidgets includes its own wxTreeListCtrl. That is NOT the same as the wxCode one.


Nice contributed class. Standard in wxPython. If you want it in C++ :

See Also