It is recognized that the CheckedListBox is selected

I still have not dealt with checkedListBox1. The program I want to do will benefit from its use, and not to use the many flags.

I have a code:

private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) { int selected = checkedListBox1.SelectedIndex; this.Text = checkedListBox1.Items[selected].ToString(); } 

The problem is that every time I click on a field and it is highlighted, it selects the selected object. I am looking to recognize changes in the selected rather than the highlighted.

What I also want to know says that if the first index element in CheckListBox is checked, as well as the third, how would I check if this is true or not?

I am sure that I will come up with this in the end, but it will help a lot to see the code.

Say I have 3 boxes: Insert A = messageBox.Show ("a"); Insert B = messageBox.Show ("b"); Insert C = messageBox.Show ("c");

Only mbox will be displayed if checked. I want to know how to do this in order to check if, for example, A and C are checked, so that if I clicked the button, the two message boxes would display "a" and then "c"

+5
c # winforms checkedlistbox selectedindexchanged
Oct. 25
source share
2 answers
  private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) { // a checkbox is changing // but value is not updated yet } private void checkedListBox1_MouseUp(object sender, MouseEventArgs e) { Debug.WriteLine(checkedListBox1.CheckedItems.Count); Debug.WriteLine(checkedListBox1.CheckedItems.Contains(checkedListBox1.Items[0])); } 

I think you should check it in MouseUp to see if the first one is checked. and _ItemCheck - this is when the checkbox changes, but the value is not yet updated.

See link: http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.items.aspx

  // First show the index and check state of all selected items. foreach(int indexChecked in checkedListBox1.CheckedIndices) { // The indexChecked variable contains the index of the item. MessageBox.Show("Index#: " + indexChecked.ToString() + ", is checked. Checked state is:" + checkedListBox1.GetItemCheckState(indexChecked).ToString() + "."); } // Next show the object title and check state for each item selected. foreach(object itemChecked in checkedListBox1.CheckedItems) { // Use the IndexOf method to get the index of an item. MessageBox.Show("Item with title: \"" + itemChecked.ToString() + "\", is checked. Checked state is: " + checkedListBox1.GetItemCheckState(checkedListBox1.Items.IndexOf(itemChecked)).ToString() + "."); } 
+6
Oct 25
source share

If you want to get a collection of all checked items, use checkedListBox1.CheckedItems. To display all marked items when a button is pressed, use the following command:

 private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++) MessageBox.Show(checkedListBox1.CheckedItems[i].ToString()); } 

If you only need their indexes, use checkedListBox1.CheckedIndices instead.

+1
Jan 25 '15 at 2:01
source share



All Articles