Solved

Problem in Disabling Checkbox in CListCtrl

Posted on 2001-07-02
9
646 Views
Last Modified: 2013-11-20
Hi,
I have created checkbox in CListCtrl using SetExtendedStyle API. I want to know to disable the checkboxes so that user cannot select them.
Bye,
Bharadwaz
0
Comment
Question by:gbharadwaz
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 22

Expert Comment

by:ambience
ID: 6244378
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 www.codegur.com and www.codeproject.com
0
 

Expert Comment

by:gilad_no
ID: 6244566
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
0
 
LVL 12

Expert Comment

by:migel
ID: 6245198
Hi!
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,
          (LPARAM)LVIS_STATEIMAGEMASK);
     // 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);
}
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 22

Expert Comment

by:ambience
ID: 6247249
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 ????
0
 
LVL 12

Expert Comment

by:migel
ID: 6247484
to ambience>>
Why by default??
you can set several state images not only two.
Just not use extended style but use SetImageList (..., LVSIL_STATE);
0
 

Author Comment

by:gbharadwaz
ID: 6247703
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.
0
 
LVL 12

Accepted Solution

by:
migel earned 200 total points
ID: 6247807
Hi!
>>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 :-)
0
 

Author Comment

by:gbharadwaz
ID: 6254839
Thanks..it worked out:)
0
 
LVL 12

Expert Comment

by:migel
ID: 6254858
but why B???
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 136
windows 10 how make picture as desktop background 2 63
either24  challenge 19 97
sumHeights2  challenge 7 107
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question