Which CheckedListBox event triggers after a item is checked?

前端 未结 12 570
攒了一身酷
攒了一身酷 2020-11-28 13:24

I have a CheckedListBox where I want an event after an item is checked so that I can use CheckedItems with the new state.

Since ItemChecked is fired before

12条回答
  •  误落风尘
    2020-11-28 13:48

    Don't know if this applies but I wanted to use a checklistbox to filter results. So as the user checked and unchecked items I wanted the list to show\hide items.

    I was having some issues which led me to this post. Just wanted to share how I did it without anything special.

    Note: I have CheckOnClick = true but it would probably still work without

    The event I use is "SelectedIndexChanged"

    the enumeration I use is ".CheckedItems"

    This give the results I think we may expect. So simplified it comes down to ....

    private void clb1_SelectedIndexChanged(object sender, EventArgs e)
    {
       // This just spits out what is selected for testing
       foreach (string strChoice in clb1.CheckedItems)
       {
          listBox1.Items.Add(strChoice);
       }
    
       //Something more like what I'm actually doing
       foreach (object myRecord in myRecords)
       {
            if (clb1.CheckItems.Contains(myRecord["fieldname"])
            {
                //Display this record
            }
       }
    
    }
    

提交回复
热议问题