views:

284

answers:

2

I have a list box and i am trying to get currently checked item inside ItemCheck Handler , but i couldn't , ->I can get List of CheckedItems using property chckdLstBox_Metabolites.CheckedItems But how do i get the item that is checked just before????

A: 

The ItemCheckEventArgs argument in your handler will give you the index of the item that is going to have its status changed. It has properties for the current value as well as a property to get or set the new value.

To get the item itself, you can use a line of code like below.

object o = checkedListBox1.Items[e.Index]; // e is ItemCheckEventArgs
Anthony Pegram
+3  A: 

You can use the event's ItemCheckEventArgs:

private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
    {
        //Note: MessageBox is for demo use only 
        MessageBox.Show("Selected Index: " + e.Index.ToString());
        MessageBox.Show("Current Value: " + e.CurrentValue.ToString());
        MessageBox.Show("New Value: " + e.NewValue.ToString());
        //Getting the item would be:
        string currentItem = (string)this.checkedListBox1.Items[e.Index];
        MessageBox.Show("Current Item: " + currentItem);
    } 
Jojo Sardez