A multi-check ListBox

CMultiCheckListBox example  Download Source Code and Example project


I had a desire/requirement on a recent project to have a CCheckListbox class that allowed for more than one checkbox in front of the string. The 3-state style set by the CCheckListbox simply didn't do what I wanted or needed. I had a list of people who could fall into 2 different categories at the same time. The 3-state style told me that this person fell into one category, but I had to just know WHICH one.

So, I decided to write a class that extended the capabilities of the CCheckListbox. What I came up with was the CMultiCheckListBox class. What it does is add another checkbox in front of the original checkbox in the CCheckListbox implementation.

To use the class, follow these steps:
  • Add a member variable to the desired class (CDialog, CFormView, etc.)
     CMultiCheckListBox m_List; 
  • Subclass the list box variable just created.
    
     void CCharityReportDlg::DoDataExchange(CDataExchange* pDX)
     {
        CDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CCharityReportDlg)
        DDX_Control(pDX, IDC_LIST1, m_List);
        //}}AFX_DATA_MAP
     }
                
  • To set the first checkbox for listbox item nIndex, call SetCheck(nIndex, nCheck)
     m_List.SetCheck(nIndex,1); 
  • To set the second checkbox, call SetMultiCheck(nIndex, nCheck)
     m_List.SetMultiCheck(nIndex,1); 
  • To retrieve the checkbox state of the first checkbox, call GetCheck(nIndex)
     m_List.GetCheck(nIndex); 
  • To retrieve the checkbox state of the second checkbox, call GetMultiCheck(nIndex)
     m_List.MultiGetCheck(nIndex); 

Last updated: 4 July 1998



Comments

  • No Error

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

    Originally posted by: Yakov

    No Error. Pls delete in file " MultiCheckListBox.cpp"
    lines in AFX_CHECKLIST_STATE::_AFX_CHECKLIST_STATE():

    for Windows NT.
    // if (afxData.bWin4 || AfxGetCtl3dState()-//>m_pfnSubclassDlgEx != NULL)
    // VERIFY(bitmap.LoadBitmap(AFX_IDB_CHECKLISTBOX_95));
    // else

    Reply
  • Error when use MFC in a Static Library

    Posted by Legacy on 01/13/1999 12:00am

    Originally posted by: Franck Buland


    When compiling with "use MFC in a Static Library", in Debug mode or in Release mode, I obtain the following messages:

    Linking...
    nafxcw.lib(winctrl3.obj) : error LNK2005: "public: __thiscall _AFX_CHECKLIST_STATE::_AFX_CHECKLIST_STATE(void)" (??0_AFX_CHECKLIST_STATE@@QAE@XZ) already defined in MultiCheckListBox.obj
    nafxcw.lib(winctrl3.obj) : error LNK2005: "public: virtual __thiscall _AFX_CHECKLIST_STATE::~_AFX_CHECKLIST_STATE(void)" (??1_AFX_CHECKLIST_STATE@@UAE@XZ) already defined in MultiCheckListBox.obj
    nafxcw.lib(winctrl3.obj) : error LNK2005: "class CProcessLocal<class _AFX_CHECKLIST_STATE> _afxChecklistState" (?_afxChecklistState@@3V?$CProcessLocal@V_AFX_CHECKLIST_STATE@@@@A) already defined in MultiCheckListBox.obj
    Release/CheckBoxTest.exe : fatal error LNK1169: one or more multiply defined symbols found

    Reply
  • error!?

    Posted by Legacy on 01/05/1999 12:00am

    Originally posted by: konrad

    Doesn't work with vc6.0
    #include <afximpl.h> not found

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

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • In this webinar, IDC featured speaker Steve Conway, Vice President of High Performance Computing, will present an update on the global x86 HPC cluster market. The presentation will include IDC's five-year forecast for the medium- to large-scale technical computing and data analysis emerging markets by systems, processors and application middleware. Cray's featured speaker, John Lee, Vice President of Cray Cluster Advanced Technology Systems, will present the new Cray® CS400™ cluster series based on …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds