|
-
Aug 5th, 2007, 08:52 PM
#5
Re: Help with Checkedlistbox
SelectedIndexChanged is NOT what you want. Selecting an item and checking an item are two completely different things. Selecting an item is exactly the same as it is in a regular ListBox. Selected items are highlighted in blue by default. Checking an item means ticking the box beside it. An item can be checked without being selected, or it can be selected without being checked, or it can be neither or it can be both. That's why the control has a SelectedItems collection and a CheckedItems collection: because they are not the same thing. The SelectedIndexChanged event is raised when the SelectedIndex property value changes, which may coincide with an item being checked but will not always as it has no specific connection.
This is just another example of why you need to read the relevant documentation, especially when things don't work the way you expect. Had you done so you'd have seen this:
The check state is not updated until after the ItemCheck event occurs.
which means that the CheckedItems collection will not yet have changed when you're looking at it. More reading of the documentation would have revealed that the event provides an ItemCheckEventArgs object, which has CurrentValue and NewValue properties. If the CurrentValue is true and the NewValue is false then you know the item is being unchecked. The opposite is true if the item is being checked. All the information you need is at your fingertips in the MSDN library, but you'll never see it if you don't look.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|