Click here to Skip to main content
12,451,232 members (55,747 online)
Click here to Skip to main content
Add your own
alternative version


44 bookmarked

CCheckComboBox II

, 4 Jul 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
A ComboBox that has a checkbox by each of its items.

Sample Image - CheckComboBox.png


This control is actually a modification of the CCheckComboBox class that was written by Magnus Egelberg, Lunalogik. Magnus' control had just about everything I was looking for in a CheckComboBox except one small feature. It did not allow you to check an item in the static text portion of the combo box, you had to drop down the list box in order to make the selections. All the drawing code in this class was written by Magnus. The only additions I made was the code to handle the check box in the static text area, and I removed the dependency on the item data for storing the check state of the items. It is now stored in a CByteArray member variable.


To use the control, you have to include the CheckComboBox.h header file and add the CheckComboBox.cpp file to your project.

If the control is used on a dialog, it has to have the CBS_DROPDOWNLIST and CBS_OWNERDRAWVARIABLE combo box styles.

Command Notifications

In addition to the regular CBN_* notifications that are generated by the combobox, the CCheckComboBox will also generate a BN_CLICKED notification whenever a user changes the check state of a check box. You can handle the BN_CLICKED notification exactly the same way you would handle it if it was generated by a button control. Use the GetCurSel() member function to get the index of the checkbox that generated the BN_CLICKED notification.

BEGIN_MESSAGE_MAP(CCCheckCombo_demoDlg, CDialog)
    // use the ON_BN_CLICKED macro to catch the BN_CLICKED
    // command that is generated by the CCheckComboBox
void CCCheckCombo_demoDlg::OnCheckBox()
    int sel = m_CheckCombo.GetCurSel();
    CString text;
    m_CheckCombo.GetLBText(sel, text);
    BOOL checked = m_CheckCombo.GetCheck(sel);
    TRACE(_T("Item %d (\"%s\") was %s \n"), sel, 
       text, checked ? _T("checked") : _T("unchecked"));

Member Functions

These are the public member functions added to the CCheckComboBox. All CComboBox member functions can also be used.

  • BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)

    Use this function to dynamically create a CCheckComboBox control. The required combo box styles are set automatically.

    Return value

    Nonzero if successful, otherwise 0.


    dwStyle The WS_* and CBS_* styles for the control. The CBS_DROPDOWNLIST and CBS_OWNERDRAWVARIABLE styles are set automatically if they are not specified.
    rect The position and size of the CCheckComboBox.
    pParentWnd Specifies the CCheckComboBox’s parent window (usually a CDialog). It must not be NULL.
    nID Specifies the CCheckComboBox’s control ID.
  • BOOL GetCheck(int nIndex)

    Use this function to get the checked state of the check box at the specified zero based index.

    Return value

    TRUE if the check box is checked, otherwise FALSE.


    nIndex The zero based index of the check box
  • BOOL SetCheck(int nIndex, BOOL bCheck = TRUE)

    Sets the check state for the check box at the specified zero based index.

    Return value

    The previous check state. TRUE if the check box was checked, FALSE if not.


    nIndex The zero based index of the check box
    bCheck The new check state. TRUE to check the check box, FALSE to uncheck it.
  • void CheckAll(BOOL bCheck = TRUE)

    Sets the checked state of all the check boxes in the CCheckComboBox control.

    Return value

    There is no return value.


    bCheck The new check state. TRUE to check the check boxes, FALSE to uncheck them.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

PJ Arends
Canada Canada
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionHow to increase size of dropdown list to show more number of element? Pin
Anurag Daware2-Jun-15 22:33
memberAnurag Daware2-Jun-15 22:33 
AnswerRe: How to increase size of dropdown list to show more number of element? Pin
PJ Arends4-Jun-15 12:09
professionalPJ Arends4-Jun-15 12:09 
GeneralRe: How to increase size of dropdown list to show more number of element? Pin
Anurag Daware7-Jun-15 22:40
memberAnurag Daware7-Jun-15 22:40 
QuestionCCheckComboBox II & Pin
Eran SMS10-Jul-13 21:59
memberEran SMS10-Jul-13 21:59 
GeneralSome features ! Pin
Bui Tan Duoc21-Mar-11 16:02
memberBui Tan Duoc21-Mar-11 16:02 
QuestionHow can I use this control on a dialog bar ? Pin
mesajflaviu11-Jan-11 8:01
membermesajflaviu11-Jan-11 8:01 
GeneralI create a VC2008 project, failed to used your code, when addstring function is invoked, software crashed Pin
skysailor_x19-Apr-10 3:02
memberskysailor_x19-Apr-10 3:02 
QuestionWhy SELCHANGE was called twice? Pin
quyun14-Feb-10 2:08
memberquyun14-Feb-10 2:08 
QuestionUsing this control in ATL Pin
Rajkumar Rachoti9-Nov-06 2:10
memberRajkumar Rachoti9-Nov-06 2:10 
Questionc# code Pin
mrinal1227-Oct-06 13:06
membermrinal1227-Oct-06 13:06 
AnswerRe: c# code Pin
PJ Arends27-Oct-06 17:27
memberPJ Arends27-Oct-06 17:27 
GeneralDisabling item selection from dropdown list box Pin
Daalu20-Sep-06 22:38
memberDaalu20-Sep-06 22:38 
GeneralRe: Disabling item selection from dropdown list box Pin
PJ Arends21-Sep-06 8:19
memberPJ Arends21-Sep-06 8:19 
GeneralUsage question... Pin
soonaz30-Aug-06 5:26
membersoonaz30-Aug-06 5:26 
GeneralRe: Usage question... Pin
PJ Arends30-Aug-06 6:07
memberPJ Arends30-Aug-06 6:07 
Generalgood... but... Pin
Min-Seok Kim26-Jul-05 1:53
memberMin-Seok Kim26-Jul-05 1:53 
GeneralComment Pin
mcbain30-Dec-03 1:00
membermcbain30-Dec-03 1:00 
GeneralRe: Comment Pin
PJ Arends30-Dec-03 7:04
memberPJ Arends30-Dec-03 7:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web02 | 2.8.160826.1 | Last Updated 5 Jul 2004
Article Copyright 2003 by PJ Arends
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid