如何通一的CheckBoxList,并找到什么检查,不检查回路 [英] How to loop thru a checkboxlist and to find what's checked and not checked

查看:99
本文介绍了如何通一的CheckBoxList,并找到什么检查,不检查回路的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图环通一个复选框列表中的项目。如果它被选中,我要设置1的值。如果没有,我想设置其他值。我用的是下面的,但它只是给我检查的项目:

 的foreach(DataRowView的myRow在clbIncludes.CheckedItems)
{
    MarkVehicle(myRow);
}
 

TIA!

解决方案

 的for(int i = 0; I< clbIncludes.Items.Count;我++)
  如果(clbIncludes.GetItemChecked(i))的
    //做选择的东西
  其他
    //做未选择的东西
 

如果该检查是在不确定状态,这仍然会返回true。您可能要替换

 如果(clbIncludes.GetItemChecked(I))
 

 如果(clbIncludes.GetItemCheckState(一)== CheckState.Checked)
 

如果你想只包括实际检查的项目

i'm trying to loop thru items of a checkbox list. if it's checked, I want to set 1 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);
}

TIA!

解决方案

for (int i = 0; i < clbIncludes.Items.Count; i++)
  if (clbIncludes.GetItemChecked(i))
    // Do selected stuff
  else
    // Do unselected stuff

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.

这篇关于如何通一的CheckBoxList,并找到什么检查,不检查回路的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆