I have this Code for draw a diagram in a PictureBox:
private void ChkLiboData_ItemCheck(object sender, ItemCheckEventArgs e)
{
Refresh();
try
{
foreach (DataClass d in ChkLiboData.CheckedItems)
{
if (d.r == null && d.g == null && d.b == null)
{
Random r = new Random();
d.r = r.Next(0, 255);
d.g = r.Next(0, 255);
d.b = r.Next(0, 255);
DrawDiagram(d.DataList, (int)d.r, (int)d.g, (int)d.b);
}
else
{
DrawDiagram(d.DataList, (int)d.r, (int)d.g, (int)d.b);
}
Refresh();
}
}
catch { }
}
but in debug mod when I check an Item and I looked at ChkLiboData.CheckedItems I couldn’t see any Items in ChkLiboData.CheckedItems.
what am I have to do???
The event
ItemCheckis raised when the checked status of an item is about to be changed. It isn’t changed already. Let me show that with an example. The CheckedListBox contains 3 items “A”, “B” and “C”. No item is checked. Now the user checks the item “A”. The eventItemCheckis fired. The propertyCheckedItemscontains no item. In the event argse(of typeItemCheckEventArgs) you can find the index of the item which checked state is changing, a propertyCurrentValuecontaining the checked state before and a propertyNewValuecontaining the new checked state. If the user then checks item “B”, the event is fired again. This time the propertyCheckedItemscontains one item “A”. a.s.o.BTW: You can set the property
NewValuein the ItemCheck event. This gives you the possibility e.g. to prevent an item to be checked.