|
I am working with the .Net 2.0 Framework and somehow miss the possibility to only react to sort of "ItemCheckedChanged" events when using a ListView in detail mode with checkboxes enabled. I thought the ItemChecked property would do the job, but it seems that it reacts to every selection of an Item, no matter wether the Checked property changed or not. Of course I could maintain a second list with checkstates and compare it against the ListView at every "ItemChecked" event but this seems hacky. Is there a more "official" way I am overlooking? |
| Marcus Riemer Friday, September 11, 2009 1:54 PM |
I don't understand your question completely but what I understand is, 1) You want to respond to only those items which has already set the checked property to true. if yes then you can do it by implement the ItemCheck event which is raised just before the ItemChecked event. There you can get the current checked state of the item. 2) As your option to maintain another list, I would like to prefer you that use the tag property of the item instead of maintaining a second list. - Marked As Answer byMarcus Riemer Friday, September 11, 2009 3:30 PM
-
|
| AUmidh Friday, September 11, 2009 2:32 PM |
Not quite sure I understand what the issue is. TheItemCheck event occurs before the value is changed, and theItemChecked event occurs after it has changed. TheItemCheckEventArgs parameter (ItemCheck event) can tell you the CurrentValue and the value it is about to change to (NewValue).ItemCheckEventArgs.CurrentValueandItemCheckEventArgs.NewValue are both CheckState type.
Just selecting a new item will not raise either ItemCheck or ItemChecked event.
- Marked As Answer byMarcus Riemer Friday, September 11, 2009 3:30 PM
-
|
| Wole Ogunremi Friday, September 11, 2009 2:35 PM |
I don't understand your question completely but what I understand is, 1) You want to respond to only those items which has already set the checked property to true. if yes then you can do it by implement the ItemCheck event which is raised just before the ItemChecked event. There you can get the current checked state of the item. 2) As your option to maintain another list, I would like to prefer you that use the tag property of the item instead of maintaining a second list. - Marked As Answer byMarcus Riemer Friday, September 11, 2009 3:30 PM
-
|
| AUmidh Friday, September 11, 2009 2:32 PM |
Not quite sure I understand what the issue is. TheItemCheck event occurs before the value is changed, and theItemChecked event occurs after it has changed. TheItemCheckEventArgs parameter (ItemCheck event) can tell you the CurrentValue and the value it is about to change to (NewValue).ItemCheckEventArgs.CurrentValueandItemCheckEventArgs.NewValue are both CheckState type.
Just selecting a new item will not raise either ItemCheck or ItemChecked event.
- Marked As Answer byMarcus Riemer Friday, September 11, 2009 3:30 PM
-
|
| Wole Ogunremi Friday, September 11, 2009 2:35 PM |
Fascinating, both of you are right: Of course the ItemChecked Event does what it should do. But somehow the event is fired when the ListView is shown the first time. The ListView is "inside" a TabPage, but populated from a forms constructor. I subscribe to the ItemChecked event after populating the ListView. Everything seems fine until the TabPage containing the ListView is shown. At this moment, I get a ItemChecked Event for each checked item in the listbox. I will take a look how I can work around this. I only "need" those events were the user actually changes the state. But thanks for your help anyway!
|
| Marcus Riemer Friday, September 11, 2009 2:47 PM |
don't forget to close the question. |
| AUmidh Friday, September 11, 2009 2:58 PM |