CheckBox复选框控件
实现方式:
1.判断指定Table容器中的CheckBox是否被选中
public static bool IsCheckBox(Table tb_Object)
{
bool ret = false;
if((tb_Object.Controls != null) && (tb_Object.Controls.Count > 0))
{
foreach (TableRow tr in tbProject.Controls)
{
foreach (TableCell tc in tr.Controls)
{
foreach (Control con in tc.Controls)
{
if (con is CheckBox)
{
CheckBox cb = (CheckBox)con;
if (cb.Checked)
{
ret = true;
}
}
}
}
}
}
return ret;
}
2.通用的递归遍历方式
private static bool IsCheckBox2(Control ctl)
{
bool ret = false;
if((ctl.Controls != null) && (ctl.Controls.Count > 0))
{
foreach(Control item in ctl.Controls)
{
ret = IsCheckBox2(item);
if(ret)
{
break;
}
}
}
else
{
if (ctl is CheckBox)
{
ret = (ctl as CheckBox).Checked;
}
}
return ret;
}
赞 (0)