简体   繁体   中英

How to evaluate a WinForms CheckedListBox?

I am looking for a good way to evaluate what is checked in a WinForms CheckedListBox.

I filled the box using the WYSIWYG editor in VS2008 and added values into it. I'd like to run a switch statement to control code execution based on which box is checked. What is the best way to go about doing this?

Adapted from MSDN :

foreach (var itemChecked in checkedListBox1.CheckedItems)
{
    string itemName = itemChecked.ToString();
    MessageBox.Show(itemName + " is checked.");
}

There are several other ways to review the state of a CheckedListBox. Review the MSDN documentation of that class for more.

You can validate checked checkbox using the below code. my checked list contains both text and value coming from database. Here , menu is my checkedlist name

foreach (DataRowView  itemChecked in  menu.CheckedItems)
            {
              string itemName = itemChecked["MenuName"].ToString();
              int id=Convert.ToInt32(itemChecked["MenuID"].ToString());

              }

Difficult to tell u the best way knowing so little of your specs. Surely you can loop through the listbox items and start some actions depending on what is checked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM