How can I find the name or index from the CheckedListBox list when I click on one of the list items?

And is it possible to find out information about the element on which I click not only in CheckListBox , but also let's say Label ? I want to make a button that removes this selected item from my list.

enter image description here

 private void button3_Click(object sender, EventArgs e) { bool relay = false; int nolIndex = 0; int k3 = 0; GraphPane pane = zedGraph.GraphPane; for (int i = 0; i < Program.axisList[0].sumAxis; i++) { if (Program.axisList[i].sumPoints == 0) nolIndex = i; } if (nolIndex != 0) relay = true; for (int i = 0; i < checkedListBox1.Items.Count; i++) { if ((checkedListBox1.CheckOnClick == true)||(checkedListBox1.CheckOnClick == false))&&(номер по которому кликнул) { if (i < nolIndex) { k3 = 0; checkedListBox1.Items.RemoveAt(i+k3); pane.CurveList[i + k3].IsVisible = false; pane.YAxisList[i + k3].IsVisible = false; labelOfAxis[i + k3].Visible = false; pane.XAxis.IsVisible = false; } else if ((i == nolIndex) && (i != 0)) { checkedListBox1.Items.RemoveAt(i + k3); pane.CurveList[i + 1].IsVisible = false; pane.YAxisList[i + 1].IsVisible = false; labelOfAxis[i + 1].Visible = false; pane.XAxis.IsVisible = false; } else { if (relay == true) k3 = 1; else k3 = 0; checkedListBox1.Items.RemoveAt(i + k3); pane.CurveList[i + k3].IsVisible = false; pane.YAxisList[i + k3].IsVisible = false; labelOfAxis[i + k3].Visible = false; pane.XAxis.IsVisible = false; } } } k3 = 0; } 

    1 answer 1

    CheckedListBox has a CheckedItems property (you can also see the SelectedItems property) - it returns a collection of checked items in this CheckedListBox control. Read the documentation

    To track item selection changes, you need to handle the ItemCheck event — the handler is passed the ItemCheckEventArgs argument, through which you can find out which item was checked (or the checkbox was cleared). Read more in the documentation.

    • I can’t figure it out. - Andy
    • @Andy what's your problem? - RussCoder
    • All figured out. - Andy
    • @Andy If the answer helped you and there are no more questions, accept it. - RussCoder