Click here to Skip to main content
11,505,005 members (67,726 online)
Click here to Skip to main content

An Enhanced CCheckComboBox

, 10 Dec 2002 122.8K 3.2K 66
Rate this:
Please Sign up or sign in to vote.
hybrid control simulating a combo box with checkboxes on a dropdown tree
<!-- Download Links --> <!-- Article image -->

Sample Image - CheckCmb.gif

<!-- Add the rest of your HTML here -->

Introduction

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 had required the class to be completely rewrote.

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 CWnd or CComboBox. I think this approach has several advantages.

To integrate these classes in a new project you would have to:

  1. Add the files "Check*" to your project
  2. On your form add a button with owner draw style and map it to a control
  3. Change the name of the mapped control to "CCheckComboBox"

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 "GetCheck".

// 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();

Any suggestions to improve this set of classes are welcome.

History

  • 6 June 2002 - I let CTreeView alone interpret user keys, and introduced the OnGetDlgCode function for the combo.
  • 11 Dec 2002 - In this update I fixed 2 bugs and I added a functionality.

License

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

Share

About the Author

Magerusan Grigore Cosmin
Web Developer
Romania Romania
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++.

Comments and Discussions

 
QuestionCan u have the edit function Pin
Member 1015708815-Jul-13 19:57
memberMember 1015708815-Jul-13 19:57 
QuestionI added "afx_msg void OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult);" to CCheckTreeCtrl,but no any effect Pin
paniclp10-Jan-12 15:45
memberpaniclp10-Jan-12 15:45 
QuestionHow can i use your Control in a CToolBar? Pin
BigJorgos30-May-08 9:40
memberBigJorgos30-May-08 9:40 
QuestionHow to update parent control Pin
Johannes P. Hansen1-Nov-07 23:44
memberJohannes P. Hansen1-Nov-07 23:44 
GeneralCheckBoxes Pin
Pandele Florin23-Aug-05 5:26
memberPandele Florin23-Aug-05 5:26 
GeneralA tip to update text whenever we have to DeleteString(nIndex). Pin
Scott M.G. Su6-Jul-05 23:00
memberScott M.G. Su6-Jul-05 23:00 
GeneralAdd Mouse Wheel Scrolling Support Pin
xzackely10-Dec-03 4:14
memberxzackely10-Dec-03 4:14 
QuestionVC++ 2003? Pin
Stefan Dahlin15-Sep-03 7:47
memberStefan Dahlin15-Sep-03 7:47 
AnswerRe: VC++ 2003? Pin
Stefan Dahlin16-Sep-03 0:30
memberStefan Dahlin16-Sep-03 0:30 
GeneralMinor improvements Pin
Göran Lundberg30-Mar-03 20:59
sussGöran Lundberg30-Mar-03 20:59 
GeneralGood, but BIG PROBLEM!!! Pin
oleg_cherkasenko15-Mar-03 6:25
memberoleg_cherkasenko15-Mar-03 6:25 
GeneralToolTip Pin
Brad Bruce22-Feb-03 9:29
memberBrad Bruce22-Feb-03 9:29 
GeneralWell done ! Pin
Anonymous12-Dec-02 3:24
sussAnonymous12-Dec-02 3:24 
GeneralNew update available Pin
Magerusan Grigore Cosmin11-Dec-02 20:51
memberMagerusan Grigore Cosmin11-Dec-02 20:51 
GeneralLooks not bad! Pin
Philip Patrick12-Aug-02 11:00
memberPhilip Patrick12-Aug-02 11:00 
GeneralBUG: Could not check, if item level decreases. Pin
Ismail PAZARBASI19-Jun-02 14:56
memberIsmail PAZARBASI19-Jun-02 14:56 
GeneralBug Pin
Boris Ilijic19-Jun-02 6:57
memberBoris Ilijic19-Jun-02 6:57 
GeneralVery Good!! Pin
WREY10-Jun-02 10:40
memberWREY10-Jun-02 10:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 11 Dec 2002
Article Copyright 2002 by Magerusan Grigore Cosmin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid