我试图环通一个复选框列表中的项目。如果它被选中,我要设置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.