如何遍历复选框列表并查找已选中和未选中的内容? [英] How to loop through a checkboxlist and to find what's checked and not checked?
本文介绍了如何遍历复选框列表并查找已选中和未选中的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图遍历复选框列表中的项目。如果选中,我要设置一个值。如果没有,我想设置另一个值。我正在使用以下内容,但只给了我已检查的项目:
I'm trying to loop through items of a checkbox list. If it's checked, I want to set a value. If not, I want to set another value. I was using the below, but it only gives me checked items:
foreach (DataRowView myRow in clbIncludes.CheckedItems)
{
MarkVehicle(myRow);
}
推荐答案
for (int i = 0; i < clbIncludes.Items.Count; i++)
if (clbIncludes.GetItemChecked(i))
// Do selected stuff
else
// Do unselected stuff
如果支票处于不确定状态,这仍将返回true 。您可能要替换
If the the check is in indeterminate state, this will still return true. You may want to replace
if (clbIncludes.GetItemChecked(i))
with
if (clbIncludes.GetItemCheckState(i) == CheckState.Checked)
如果您只想包含实际检查的项目。
if you want to only include actually checked items.
这篇关于如何遍历复选框列表并查找已选中和未选中的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文