CCheckComboBox: A ComboBox with a Checked Tree Dropdown


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

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("UK",     7, ROOT_LEVEL + 2);

//## CHECK all items

//## UNCHECK the item with ID = 6
m_choCountries.SetCheck(6, FALSE);

//## GET all checked items
CString strCheckedItems = m_choCountries.GetCheckedIDs();


Download demo project - 51 Kb


  • I found many mistakes

    Posted by zizzzz on 11/02/2006 03:38pm

    like 'CTreeCtrl::CreateEx'B_: don't deaserve 8 parameters

    • error

      Posted by zlristovski on 04/18/2009 01:32pm

      And anyone who fix tis problem with 8 parameters

  • Debug Error in vs 2005 bate2

    Posted by paraGOD on 10/25/2005 11:01am

    Hi guys, when I use this source code in vs2005,Assert error occured.The following is the code:ASSERT((dwStyle & WS_POPUP) == 0); Can someone give me some help?thanks para

    • Re: Debug Error in vs 2005 bate2

      Posted by creeh on 07/10/2006 02:44pm

      Hi I am getting the same Assert error and wondered if you found a solution to it. The functionality seems to work fine, it is just asserting. Chris

  • Nice work!

    Posted by Legacy on 12/22/2003 08:00am

    Originally posted by: miro kundacina

    very very nice work,
    thank you.
    kmiro, kmiro@narat.co.yu

  • Error in using in MDI window

    Posted by Legacy on 03/17/2003 08:00am

    Originally posted by: mask

    I am getting assertion fail error when using the control in MDI (form) window.

    Steps to reproduce it

    1) open the two mdi windows which contain the checkedtree combo control in it.

    2) Select the combobox in mdi second mdi window.

    3) now close the first mdi window.

    second mdi window will not refresh properly now.
    if you close the second mdi window it throws assertion failed.

    I am not sure it is because of "static WNDPROC CCheckComboBox::m_parentWndProc"

    Unintercept replaces wrong m_parentWndProc?

    Again i may be wrong. I will be very much thankful if you help me in resolving this.

    Thanks &Regards

    • Error also by using the control in multiple dialogs

      Posted by oystein on 04/28/2004 11:44am

      Hi, I get exactly the same problems as you Mask, when using forms. I also tried to reproduce the error using an extra dialog in the demoproject. 1: Use the demoproject as it is 2: Add a test-button in the SampleDlg 3: Make a new simple test-dialog with one CCheckComboBox item, and connect this to the test-button. 4: Run the project, and i.e uncheck europe from the "Countries" CheckComboBox. 5: Push the test-button, the test-dialog will now freeze.. At first I thought this code was excactly what I was looking for, but it seems to be unable to use in my project because of this problem. If anyone can help me, I will be very thankful! Regards Oystein

  • What about shift one place up and down functionality

    Posted by Legacy on 02/24/2003 08:00am

    Originally posted by: gracias carol

    hi it looks to me that u have done good work in tree control , i am looking for adding the right click menu pop up option of shift up and shift down on the selected node of tree control. Need help on it right now my cut/copy/paste/drag/drop are working fine.

    Waiting for an reply

  • Nice work!

    Posted by Legacy on 01/18/2003 08:00am

    Originally posted by: Ahmed Ceder

    Nice work ..

    I was looking for something like this.
    thanx a lot.

  • Anyone convert this to COM?

    Posted by Legacy on 01/03/2003 08:00am

    Originally posted by: mburt

    I have need for this control, but in a VB environment.
    Has anyone attempted converting this class to a COM object?

  • A ComboBox with a Checked Tree Dropdown

    Posted by Legacy on 12/19/2002 08:00am

    Originally posted by: prabir

    U have given a very good idea. but sir can this be done in
    visual basic 6.0.If so, how ??

    Thanking u

  • Is there a reason to parent the treectrl to the desktop

    Posted by Legacy on 12/09/2002 08:00am

    Originally posted by: Glen Smith

    Very good job, Simple but effective. l just was wondering why the tree control is parented to the destop and not the dialog?

  • how to rewrite it with c#?

    Posted by Legacy on 11/01/2002 08:00am

    Originally posted by: sunhs

    you have done an excellent job,but how to rewrite it with c#?

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date