Click here to Skip to main content
13,355,311 members (58,847 online)
Click here to Skip to main content
Add your own
alternative version


70 bookmarked
Posted 9 Jan 2000

Adding Checkboxes to a list control

, 9 Jan 2000
Rate this:
Please Sign up or sign in to vote.
Using the updated list control in IE3 and above to add check boxes to your list controls

A list view gives the GUI designer many options. One of the best is the ability to display tabular data in columns, sort columns, add images and more. This is well implemented by CListView in MFC.

A checked list box enables the GUI designer to get the users picked options via a checkbox on every list item. This is well implemented by CCheckListBox in MFC.

How to combine them both into one control?

Basically, there are two options: either you use owner drawn list view controls and draw your own check boxes as small images OR you can use the new control introduced in Microsoft's IE 3.0. To use the new features of a list view control you must install IE 3.0 (or above) to get the newest version of COMCTL32.DLL (the common controls library).

This control introduces some new flags in the ListView style and adds accepts some macros defined in the windows header files.

Bear in mind, the new flags and macros DO NOT APPEAR in VC++ 4.2 help files and started to exists in help files only from MSDN Jan 97 version and V++ 5.0

Well, here goes:

First, you have to set the new style in the list view control. This can be done by:


This sets the list view to support check boxes and also a full row select (not only the 1st column).

LVS_EX_CHECKBOXESThe control supplies check boxes for each item. You can retrieve the state of the check box by using the ListView_GetCheckState macro.
LVS_EX_FULLROWSELECTWhen an item is selected, all of its subitems are also displayed as elected. Clicking on any subitem will select the entire row. This extended style is only effective in conjunction with the LVS_REPORT style.
LVS_EX_GRIDLINESDashed gridlines are displayed around all items and subitems. This extended style is only effective in conjunction with the LVS_REPORT style.
LVS_EX_HEADERDRAGDROPEnables drag-and-drop re-ordering of the columns in the ListView. This extended style is only effective in conjunction with the LVS_REPORT style.
LVS_EX_SUBITEMIMAGESAllows images to be displayed for subitems. This extended style is only effective in conjunction with the LVS_REPORT style.
LVS_EX_TRACKSELECTEnables hot tracking of items in a ListView control. Hot Tracking, also known as Hover Selection, means that an item is automatically selected when the mouse pointer is over it for more than 1 second. This style applies to all styles of the ListView control.

How to get notification when an item is checked / unchecked:

void DemoDlg::OnItemchangedLinksList(NMHDR* pNMHDR, LRESULT* pResult) 
    *pResult = 0;

    if (pNMListView->uOldState == 0 && pNMListView->uNewState == 0)
        return;    // No change

    // Old check box state
    BOOL bPrevState = (BOOL)(((pNMListView->uOldState & 
    if (bPrevState < 0)    // On startup there's no previous state 
        bPrevState = 0; // so assign as false (unchecked)

    // New check box state
    BOOL bChecked = <BR>            (BOOL)(((pNMListView->uNewState & LVIS_STATEIMAGEMASK)>>12)-1);   
    if (bChecked < 0) // On non-checkbox notifications assume false
        bChecked = 0; 

    if (bPrevState == bChecked) // No change in check box
    // Now bChecked holds the new check box state

    // ....

for this to work, you must map the following message:


Setting the check box state of an item:

Try the following piece of code

void SetLVCheck (WPARAM ItemIndex, BOOL bCheck)
    ListView_SetItemState (m_lvTestList.m_hWnd, ItemIndex, 
        UINT((int(bCheck) + 1) << 12), LVIS_STATEIMAGEMASK);

Getting the check box state of an item:

Use the macro ListView_GetCheckState(hwndLV, i) defined in commctl.h (hwndLV is the window handle of the list view member - i.e, m_lvTestList.m_hWnd and i is the list view index)


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

Eran Yariv
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionHi Pin
Binni shah9-Mar-12 19:15
memberBinni shah9-Mar-12 19:15 
Question&gt;&gt;12)-1 ? Pin
_pw28-Nov-05 0:03
member_pw28-Nov-05 0:03 
AnswerRe: &gt;&gt;12)-1 ? Pin
dontknowitall6-May-07 15:31
memberdontknowitall6-May-07 15:31 
QuestionHow to select only one check box ? Pin
dhawan_boss@yahoo.com12-Sep-05 23:59
memberdhawan_boss@yahoo.com12-Sep-05 23:59 
QuestionHow to select only one check box ? Pin
Anonymous12-Sep-05 23:55
sussAnonymous12-Sep-05 23:55 
GeneralThanks Pin
tsurutsuru17-Mar-05 10:57
membertsurutsuru17-Mar-05 10:57 
GeneralGreat article Pin
Trapper300115-Dec-03 16:24
memberTrapper300115-Dec-03 16:24 
QuestionHow to use OnItemchangedLinksList Pin
Michael Klim19-Oct-03 8:07
memberMichael Klim19-Oct-03 8:07 
Questionhow to add a check box and item without a check box in a single column Pin
abhijeet4all25-Sep-03 3:52
memberabhijeet4all25-Sep-03 3:52 
QuestionHow to disable check box within ctrlList,thanks Pin
nodream16-Jun-03 1:02
membernodream16-Jun-03 1:02 
GeneralI want partly checkbox in one column Pin
sandmanq29-Mar-03 2:43
susssandmanq29-Mar-03 2:43 
GeneralRe: I want partly checkbox in one column Pin
lvidaguren18-Feb-04 19:58
memberlvidaguren18-Feb-04 19:58 
QuestionHow can set all column with checkbox? Pin
sages10-Mar-03 23:23
susssages10-Mar-03 23:23 
AnswerRe: How can set all column with checkbox? Pin
Saravanan_article23-Dec-05 22:13
memberSaravanan_article23-Dec-05 22:13 
The same problem here also..
GeneralSetLVCheck doesn't seem to work Pin
prospector89-Mar-03 16:22
memberprospector89-Mar-03 16:22 
GeneralRe: SetLVCheck doesn't seem to work Pin
j2xuk28-Mar-04 21:33
memberj2xuk28-Mar-04 21:33 
GeneralRe: SetLVCheck doesn't seem to work Pin
tidi28-Jul-04 22:58
membertidi28-Jul-04 22:58 
Questionhow to get the the header 's text of every column Pin
dvid6-Mar-03 17:10
memberdvid6-Mar-03 17:10 
GeneralAdding Check Box to List COntrol Pin
Anonymous4-May-02 15:07
memberAnonymous4-May-02 15:07 
Generalproblem with common controls 6.0 Pin
DaveBevan3-Apr-02 15:22
memberDaveBevan3-Apr-02 15:22 
QuestionCan u please tell me how to include Comctl32.dll to existing project environment Pin
Ravi ;-)3-Dec-01 21:28
memberRavi ;-)3-Dec-01 21:28 
Questioncan someone explain ListView_SetItemState(...) Pin
Anonymous18-Jul-01 15:33
memberAnonymous18-Jul-01 15:33 
Generalsimple sample Pin
erez17-May-01 3:00
membererez17-May-01 3:00 
GeneralThis is great Pin
SP3-Apr-01 14:41
memberSP3-Apr-01 14:41 
QuestionHow to disable check box within ctrlList Pin
Anonymous25-Mar-01 23:53
memberAnonymous25-Mar-01 23:53 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 10 Jan 2000
Article Copyright 2000 by Eran Yariv
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid