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 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


Comments

  • I found many mistakes

    Posted by zizzzz on 11/02/2006 07:38am

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

    • error

      Posted by zlristovski on 04/18/2009 06:32am

      And anyone who fix tis problem with 8 parameters

      Reply
    Reply
  • Debug Error in vs 2005 bate2

    Posted by paraGOD on 10/25/2005 04: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 07:44am

      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

      Reply
    Reply
  • Nice work!

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

    Originally posted by: miro kundacina

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

    Reply
  • Error in using in MDI window

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

    Originally posted by: mask

    Hi 
    
    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.

    error:
    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
    Mask


    • Error also by using the control in multiple dialogs

      Posted by oystein on 04/28/2004 04: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

      Reply
    Reply
  • What about shift one place up and down functionality

    Posted by Legacy on 02/24/2003 12: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
    gracias

    Reply
  • Nice work!

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

    Originally posted by: Ahmed Ceder

    Nice work ..

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

    Reply
  • Anyone convert this to COM?

    Posted by Legacy on 01/03/2003 12: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?

    Reply
  • A ComboBox with a Checked Tree Dropdown

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

    Originally posted by: prabir

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

    Thanking u
    prabir

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

    Posted by Legacy on 12/09/2002 12: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?

    Reply
  • how to rewrite it with c#?

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

    Originally posted by: sunhs

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

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds