I wanted a control with both the functionality of a combo and of a tree with checkboxes. Such a control would act like a combo showing a dropdown and also allowing checking and fast checking items.
By the time I finished coding, I saw Magnus Egelberg's "
CCheckComboBox" class, but I realize that my control has several advantages which anyway would have required the class to be completely rewritten.
My implementation (of a check list dropdown) is different from other implementations I seen, using a child, and not a popup window. Also for a better generality, I use a tree, letting user see the checked items, by showing them in an edit box with a tool tip. I simulated a combo box by using an owner draw button, thus not directly deriving it from
CComboBox. I think this approach has several advantages.
To integrate these classes in a new project, you would have to:
- Add the files "Check*" to your project
- On your form, add a button with owner draw style and map it to a control
- Change the name of the mapped control to "
To add an item, you have to specify a caption, an ID and a level. The root has the level 0 (
ROOT_LEVEL). All other nodes must be added with levels greater than 0 (
ROOT_LEVEL), in the order in which they appear in the full-expanded tree. At any time, you can use the function "
GetCheckedIDs" to get a
string with all checked item's IDs on the highest level of the tree. It is also possible to get the checked IDs using the function "
m_choCountries.AddString("USA", 5, ROOT_LEVEL + 2);
m_choCountries.AddString("Canada", 6, ROOT_LEVEL + 2);
m_choCountries.AddString("UK", 7, ROOT_LEVEL + 2);
CString strCheckedItems = m_choCountries.GetCheckedIDs();
Any suggestions to improve this set of classes are welcome.
- 6th June, 2002 - I let
CTreeView alone interpret user keys, and introduced the
OnGetDlgCode function for the combo.
- 11th December, 2002 - In this update, I fixed 2 bugs and added a functionality.
This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.
A list of licenses authors might use can be found here.
In June 2002 Magerusan Grigore Cosmin, took a Master's Degree in Computer Science at UBB University in Cluj.
He has ~2 years of experience using in VC++.