Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winforms CheckedListBox get checked items in ItemCheck event

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I am trying to get all the items that are checked in a CheckedListBox when one of the check boxes is checked. I want to be able to do something with this list in the ItemCheck event.

The problem is that when you go into the event, the checkbox is not checked yet. So if I do a foreach loop on the *.Checked property, it won't be there if it was unchecked before the user checked it.

I could use the e.NewValue property, but how, since I don't know which index the item in the foreach is.

So if I do the following:

Code:
private void chkSelectStatementColumns_ItemCheck(object sender, ItemCheckEventArgs e)
{
    foreach (var itemChecked in chkSelectStatementColumns.CheckedItems)
    {
        // Use the IndexOf method to get the index of an item.
        MessageBox.Show(itemChecked.ToString());
    }
}
I don't see the one that was just checked because it isn't checked yet. Conversely, if the user unchecks an item, it WILL show up in the list, because it hasn't become unchecked yet.

Thanks,

Tom
 
Ok, my mistake, but this forum is for ASP.NET, not for winforms
try posting here: forum732
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top