Problem in Disabling Checkbox in CListCtrl

I have created checkbox in CListCtrl using SetExtendedStyle API. I want to know to disable the checkboxes so that user cannot select them.
Who is Participating?
migelConnect With a Mentor Commented:
>>Do you mean to say that instead of using SetExtendedStyle I should use SetImageList() API..
completly true
My functions is to API (hwnd as parameter)
I think that deriving class from CListCtrl and embed these functions in the class will be preffered way. Also you can set proper image list in this class without client class frustration :-)
you cant do that directly , the check-boxes can only be cleared or set.

If you want to have disabled items etc. this requires custom-drawn or owner-drawn listCtrls i.e. manage the state and draw the checkbox yourself, i suggest custom-draw for this.

You can find samples on how to do that on and
You can also set the item state to 0 to hide the check box.

0x0000 - Hide the check box
0x1000 - Cleared check box
0x2000 - Checked check box
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

imho the best way is to set State image consists of 3 items
and manually set ItemState with proper state image index
for example:

BOOL IsItemDisabled(HWND hList, int nItem)
     int nState = (int)::SendMessage(hList, LVM_GETITEMSTATE, (WPARAM)nItem,
     // Return zero if it's not checked, or nonzero otherwise.
     return ((BOOL)(nState >> 12) -1) == 2;

BOOL SetDisable(HWND hList, int nItem, BOOL bDisable)
     LVITEM lvi;
     lvi.stateMask = LVIS_STATEIMAGEMASK;

     Since state images are one-based, 1 in this macro turns the check off, and
     2 turns it on.
     lvi.state = INDEXTOSTATEIMAGEMASK((bDisable ?3 : 1));
     return (BOOL) ::SendMessage(hList, LVM_SETITEMSTATE, nItem, (LPARAM)&lvi);
migel :
how would you create state images for the control, by default it creates two state images one for set state and one for clear state ????
to ambience>>
Why by default??
you can set several state images not only two.
Just not use extended style but use SetImageList (..., LVSIL_STATE);
gbharadwazAuthor Commented:
Hi Migel,
   I am partially clear but not fully:) Do you mean to say that instead of using SetExtendedStyle I should use SetImageList() API. One more question is where should I invoke the two functions you have told. I am asking this because my list ctrl gets increased or decreased dynamically and I have to see all the check boxes are in disabled state.
gbharadwazAuthor Commented: worked out:)
but why B???
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.