How to check if an item inside a CheckBoxList is UnChecked? RRS feed

  • Question

  • Hi,

    Suppose i have three dependant checkboxlists and i want to add/remove items from the 2nd and 3rd checkboxlist on the basis of 1st/2nd.

    How can i detect if a particular item inside a checkboxlist is unchecked?

    Any example would be appreciated.


    Thursday, May 7, 2015 1:13 PM


All replies

  • You should ask questions in the forum specific to your technology so people know which you're using and you get the best support on your issues.


    I guess windows forms.

    There's an event you can handle on the CheckedListBox.

    It tells you which has changed and what the new value is.

    It fires when you check or un check.

    private void CheckedListBox1_ItemCheck(Object sender, ItemCheckEventArgs e)
    System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
    messageBoxCS.AppendFormat("{0} = {1}", "Index", e.Index );
    messageBoxCS.AppendFormat("{0} = {1}", "NewValue", e.NewValue );
    messageBoxCS.AppendFormat("{0} = {1}", "CurrentValue", e.CurrentValue );
    MessageBox.Show(messageBoxCS.ToString(), "ItemCheck Event" );


    If this is instead asp.net then the event is onselectedIndexChanged, like:

    <asp:RadioButtonList id="RadioButtonList1" 
    void Index_Changed(Object sender, EventArgs e) 
             Label1.Text = "You selected " + RadioButtonList1.SelectedItem.Text +
                         " with a value of $" + RadioButtonList1.SelectedItem.Value +
    From http://stackoverflow.com/questions/18486574/checkboxlist-item-checked-event

    Hope that helps.

    Technet articles: Uneventful MVVM; All my Technet Articles

    Thursday, May 7, 2015 2:44 PM
  • hello

    you can iterate throw a listbox very easily like this

                for (int i = 0; i < this.checkedListBox1.Items.Count; ++i )
                    if (checkedListBox1.GetItemChecked(i))
                        MessageBox.Show("checked at position "+ i as string);
                        MessageBox.Show("unchecked at position " + i as string);
    hope it he;ps
    Thursday, May 7, 2015 3:10 PM
  • The CheckedListBox control in Windows Forms has a CheckedItems that returns a collection of the the checked items: https://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.checkeditems%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

    foreach(object itemChecked in checkedListBox1.CheckedItems) {
            YourType obj = itemChecked as YourType;

    If you are using the CheckBoxList class in ASP.NET, each item in it has a Selected property: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkboxlist(v=vs.110).aspx

    Note that you should ask ASP.NET and web related questions at http://forums.asp.net and not here though.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Proposed as answer by Spiri91 Thursday, May 7, 2015 3:20 PM
    • Marked as answer by Kristin Xie Friday, May 15, 2015 9:49 AM
    Thursday, May 7, 2015 3:16 PM