MultiSelect Tree View control

MultiSelect Tree View control

This article was submitted .

This WTL MultiSelect Tree control is an extension to the regular TreeView control. It offers multiple selected items, marquee selection and as a bonus: individual item colouring and font.

You can select items by holding the CTRL key down and clicking, or use the SHIFT key to range-select. Press and drag the mousebutton to select using a rubber-band rectangle (marquee). The keyboard reacts to SHIFT selection as well.

How to use it

Add a member variable to your dialog implementation file...
CMultiSelectTreeCtrl m_tree
In the OnInitDialog() event handler, add the following line:
  LRESULT OnInitDialog(UINT /*uMsg*/, 
                       WPARAM /*wParam*/, 
                       LPARAM /*lParam*/, 
                       BOOL& /*bHandled*/)
Also add this reflection macro to your main message map:

The control offers new methods for traversing the selected items by using this sequence...

   HTREEITEM hItem = m_tree.GetFirstSelectedItem();
   while( hItem ) {
      // ...
      hItem = m_tree.GetNextSelectedItem();

In addition it exposes two new methods SetItemColors and SetItemFont that allows you to set the colours for each item.

It currently does not offer any specific rules on which items can be selected. You cannot use the old TVN_SELCHANGED notification at this point, but the control do generate some new TVN_ITEMSELECTING and TVN_ITEMSELECTED notifications. To manually select an additional item, use the enhanced SelectItem method also exposed by the control.

Source Code Dependencies

Microsoft Visual C++ 6.0
Microsoft WTL 7.5 Library

Download Files

DownloadSource Code (6 Kb)

To the top