Introduction

Sometimes, we need a tree control that allows the user to select multiple items at a time, but this feature is not provided by the standard common controls. Thanks to Richard Hazlewood's great article, this feature has been implemented nicely. However, Richard's implementation only supports the simple style rubber band selection. What I want to have is a tree control that implements an alpha-blended selection rectangle (just like explorer does).

Eugen Podsypalnikov did give us an approach to that with his CCoverWnd class, but the focus issue and CWnd derived implementation makes me think that maybe implementing the selection drawing by the tree control itself would be a better idea, so here comes the CMultiSelTriCheckTreeCtrl class in MFC.

The demo project actually belongs to my another humble article CVComboBox, so the download URLs are shared here.

As the snapshot shown, the tree control can have tri-states checkboxes display for each item, and all the selected items will be checked/unchecked when you click the checkbox of one of them. If you want to only check/uncheck the very item which is being selected, you can click the checkbox while holding the control key down.

Interfaces of CMultiSelTriCheckTreeCtrl

CMultiSelTriCheckTreeCtrl is an MFC wrapper class that encapsulates the multi-select tree control, it derives from another MFC wrapper class called CTriCheckStateTreeCtrl, which implements a tri-check state tree control.

The interfaces of CMultiSelTriCheckTreeCtrl are quite similar to those of CMultiTree by Richard Hazlewood since I just simply changed the selection drawing code after all, here are the public interfaces: