Click here to Skip to main content
Click here to Skip to main content

A multi-check ListBox

By , 12 Dec 1999
 
  • Download demo project - 15 Kb
  • Download source files - 4 Kb
  • Sample Image - multichecklistbox.jpg

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

    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

    About the Author

    Harry J. Devine
    Web Developer
    United States United States
    Member
    No Biography provided

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    General[Message Deleted]memberJAS GIRI17 Feb '09 - 1:54 

    GeneralRe: check box small examplemvpChristian Graus18 Feb '09 - 12:44 
    JAS GIRI wrote:
    plz give me code does not use checklist box and gride

     
    Why do you keep asking for code that doesn't use a checkboxlist ? If you don't use one, you'll just have to write one.
     
    Christian Graus
     
    Driven to the arms of OSX by Vista.

    QuestionCan we have items with NO checkboxes?memberGary Chapman23 May '06 - 5:47 
    GREAT article! But is it possible to have list items with no checkboxes, and if so how would I go about it?
     
    For example, I want a list that contains headings and blank lines, neither of which warrant checkboxes:
     
    ---------------------------
     
    Development Environments
     
    [x] Visual Studio
    [ ] Delphi
    [ ] VB
     

    Runtime platforms
     
    [ ] x86
    [x] Alpha
    [x] PocketPC

     
    ---------------------------
     
    Thanks,
     
    Gary
    AnswerRe: Can we have items with NO checkboxes?memberHarry J. Devine23 May '06 - 8:38 
    Based on your example, it looks like you would have to create your own class that can handle straight up text and no checkboxes, and others that have the check boxes. Couldn't you have your headings (i.e. "Development Environments" as a static label on top of your listbox, and the CCheckListBox listbox populated with your required items?
     
    Good luck,
    Harry
    GeneralDrawFrameControlmemberJavi_26 Apr '05 - 9:01 
    You don't have to paint the checkbox by yourself, you can use DrawFrameControl() function to leave Windows paint for you (in current GUI style)
    Cheers,
     
    Javi
    GeneralSample codesussAnonymous7 Feb '05 - 4:09 

    I am unable to download the samples. Can you direct me to an available link that I can do this?
    Thanks,Rich
    GeneralRe: Sample codememberHarry J. Devine7 Feb '05 - 10:39 
    You'll have to contact the Webmaster at Codeproject.com. I'm not really sure where they keep the samples at to download. Are you a member of Codeproject, because I think you have to be a member and signed in to download code and samples.
     
    Good Luck,
    Harry
    Generalmore than 2 checkboxessussrobert guy24 Oct '00 - 8:50 
    hello
     
    well, i need to know if you have a vesion of MultiCheckListBox with 3 checkboxes, if not what should i change to add another checkbox
     
    thank you
    General3D check boxessussJeremy Asbill3 Oct '00 - 10:12 
    This article helped me a great deal in doing what I need to with the CCheckListBox, but I would
    really like to have 3D check boxes in my control. I have seen controls like this in several apps
    including MS Word (I am using 97). Select Tools | Customize... and take a look at the Toolbar
    tab. Is this a CCheckListBox control
    GeneralRe: 3D check boxesmemberTom Hughes19 Dec '00 - 23:12 
    Try the following:
     
    http://codeguru.earthweb.com/listbox/CCheckList.shtml
    GeneralAdd multiple columns in ListBoxsussSanthosh Joseph19 Sep '00 - 23:45 
    It would be better to provide the fascility to have multiple columns along with the check box style . Is it possible with listbox ?
    GeneralRe: Add multiple columns in ListBoxsussHarry Devine20 Sep '00 - 9:29 
    I'm sure it would be possible, but I've never tried that sort of thing. I would imagine that you would have to make the listbox completely owner-drawn. A better way might be to make a CListCtrl class that is owner drawn.
     
    Good Luck.
     
    Harr

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

    Permalink | Advertise | Privacy | Mobile
    Web01 | 2.6.130516.1 | Last Updated 13 Dec 1999
    Article Copyright 1999 by Harry J. Devine
    Everything else Copyright © CodeProject, 1999-2013
    Terms of Use
    Layout: fixed | fluid