Problem in List

  • Thread starter Thread starter msnews.microsoft.com
  • Start date Start date
M

msnews.microsoft.com

Hi All,

I am having problem in ListViewControl which has items with CheckBoxes.

When I use the CheckState event,

the ListViewItem whatever I checked still contains the old CheckState and
has not changed to the new CheckState.

Is this a bug?

Any suggestions please?

Thanks
Anand Ganesh
 
No, it's not a bug. The event fires _before_ the change takes place in
the list view. You have to use the event arguments to determine what
the new state will be.
 
Hi Bruce,

Thanks for the Info.

Now this is getting more interesting.

I have a situation like this.

I want to collect all the items that is checked.

I wrote a loop to go through all the items and was checking item.checked ==
true ; so in this case the currently checked item was not showing up as
checked. Because I was using Check_Event and this event fires up before the
change.

So how will I solve this problem?

Thanks for helping me out.

Regards
Anand
 
Here is an (untested) example that I threw together from some code I
have:

private void listview_ItemCheck(object sender, ItemCheckEventArgs ice)
{
ArrayList checked = new ArrayList();
foreach (ListViewItem lvi in listview.CheckedItems)
{
if (lvi.Index == ice.Index)
{
if (ice.NewValue == CheckState.Checked)
{
checked.Add(lvi);
}
// otherwise exclude the list item from the "checked"
// list because its new state is "UnChecked".
}
else
{
checked.Add(lvi);
}
}
.... do something with the "checked" list ...
}
 
Back
Top