CCheckComboBox: A ComboBox with a Checked Tree Dropdown | CodeGuru

CCheckComboBox: A ComboBox with a Checked Tree Dropdown

Click here for larger image Environment: VC6, Windows 98, 2000, NT4 Often programmers meet situations when it is necessary to filter data based on a number of criteria. A solution is to implement a number of simple combos or checklist boxes. This has the disadvantage of not allowing multiple choices (combos) or taking a lot […]

Written By
CodeGuru Staff
CodeGuru Staff
Dec 18, 2002
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More





Click here for larger image

Environment: VC6, Windows 98, 2000, NT4

Often programmers meet situations when it is necessary to filter data based on a number of criteria. A solution is to implement a number of simple combos or checklist boxes. This has the disadvantage of not allowing multiple choices (combos) or taking a lot of space (checklist boxes).

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 multiple selections, and fast selection or deselection of all items.

I saw on CodeGuru other ideas, which are more or less close to what I expected from such a control but I think they lack functionality in a way or another, so I decided to write my own solution.

User keys: alt + up or down, F4 (to drop/close the dropdown) up, down (to move the selection up or down), right (to expand current item), left (to collapse current item) and space (to check or uncheck the current item).

Using CCheckComboBox: For example if you want to add 3 countries: “USA” (ID=5), “Canada” (ID=6), “UK” (ID=7), and their corresponding continents, you would have to write the following code:

//## ADD tree items:
m_choCountries.AddString(“North America”);
  m_choCountries.AddString(“USA”,    5, ROOT_LEVEL + 2);
  m_choCountries.AddString(“Canada”, 6, ROOT_LEVEL + 2);
m_choCountries.AddString(“Europe”);
  m_choCountries.AddString(“UK”,     7, ROOT_LEVEL + 2);
//## CHECK all items
m_choCountries.CheckAll(TRUE);
//## UNCHECK the item with ID = 6
m_choCountries.SetCheck(6, FALSE);
//## GET all checked items
CString strCheckedItems = m_choCountries.GetCheckedIDs();

Downloads

Download demo project – 51 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.