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*/)
{
...
m_tree.SubclassWindow(GetDlgItem(IDC_TREE1));
...
}
Also add this reflection macro to your main message map:
BEGIN_MSG_MAP(CMainDlg)
...
REFLECT_NOTIFICATIONS()
END_MSG_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.0Microsoft WTL 7.5 Library
Download Files
![]() | Source Code (6 Kb) |

