PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms Disable Checkbox ListViewItem

Reply

Disable Checkbox ListViewItem

 
Thread Tools Rate Thread
Old 13-12-2005, 06:19 PM   #1
=?Utf-8?B?U0FIVVM=?=
Guest
 
Posts: n/a
Default Disable Checkbox ListViewItem


How can I disable a listviewitem which is basically a checkbox. Suppose I
have 10 checkboxes in my ListView and I want three of them disabled so that
the user can not check/uncheck those three items.

I am using C#.

Thanks in advance for your help.
  Reply With Quote
Old 14-12-2005, 10:10 AM   #2
Claes Bergefall
Guest
 
Posts: n/a
Default Re: Disable Checkbox ListViewItem

A checkbox is in reality simply 2 different state images (one for the
checcked box and one for the unchecked box) that are taken from a system
supplied image list and applied to the listview item as appropriate.
Unfortunately .NET doesn't provide an event for when the state image index
changes so you'll have to override WndProc and handle the LVN_ITEMCHANGING
notification. Here's code that does most of this (in VB.NET):

http://groups.google.se/group/micro...e99eb3ffc?hl=sv

However, this code checks for changes to the selected state flag
(LVIS_SELECTED). Change this to check for the new state image index instead
(different bits in the state parameter) and return 1 to prevent the change
(0 to allow it). The state image index is 1 for the unchecked box and 2 for
the checked one. If you set it to 0 the checkbox will be removed

Read more using the following keywords: LVITEM, INDEXTOSTATEIMAGEMASK,
LVN_ITEMCHANGING, NMLISTVIEW

The following code should give you the state image index provided the code
in the link above (still in VB.NET):
((nmlv.uNewState And &HF000) >> 12)

/claes


"SAHUS" <SAHUS@discussions.microsoft.com> wrote in message
news:601FCB4E-B0C9-447E-BEE9-E1ED5F877E42@microsoft.com...
> How can I disable a listviewitem which is basically a checkbox. Suppose I
> have 10 checkboxes in my ListView and I want three of them disabled so

that
> the user can not check/uncheck those three items.
>
> I am using C#.
>
> Thanks in advance for your help.



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off