[英]How to evaluate a WinForms CheckedListBox?
I am looking for a good way to evaluate what is checked in a WinForms CheckedListBox. 我正在寻找一种评估WinForms CheckedListBox中所检查内容的好方法。
I filled the box using the WYSIWYG editor in VS2008 and added values into it. 我在VS2008中使用WYSIWYG编辑器填充了该框,并在其中添加了值。 I'd like to run a switch statement to control code execution based on which box is checked.
我想运行一个switch语句,以根据选中的框来控制代码的执行。 What is the best way to go about doing this?
这样做的最佳方法是什么?
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. 还有其他几种方法来检查CheckedListBox的状态。 Review the MSDN documentation of that class for more.
有关更多信息,请查看该类的MSDN文档 。
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.
当然,您可以遍历列表框项并根据所检查的内容开始一些操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.