【问题标题】:How do I unselect all selected CheckBoxes in a DataGridView如何取消选择 DataGridView 中的所有选定复选框
【发布时间】:2014-10-31 06:17:36
【问题描述】:

我想从动态生成的DataGridView中取消选中所有选中的复选框?

我尝试过如下

for (int i = 0; i < MygridView.Rows.Count; i++)
{
   DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)MygridView.Rows[i].Cells[0];
   if (cell.Value == cell.TrueValue)
   {
    // (row.Cells[CheckBoxColumn.Index] as DataGridViewCheckBoxCell).value = false;
    Need to unchecked all checked checkboxes 
   }
}

或者还有其他方法吗?

【问题讨论】:

  • 为什么是如果? cell.Value = false 或 = cell.FalseValue 应该这样做.. 或者他们是 TriState?然后离开 if 但使用您准备好的单元格变量..
  • 还有什么生成的?但除此之外,您不需要循环和强制转换。

标签: c# winforms checkbox datagridview


【解决方案1】:

试试这个:

foreach (DataGridViewRow item in MygridView)
        {
            DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)item.Cells[0];

            cell.Value = false;
        }

【讨论】:

  • 对上面我刚刚遇到的更正:在上面的代码中将 .Rows 添加到 MygridView。
猜你喜欢
  • 1970-01-01
  • 2011-10-09
  • 2011-05-17
  • 1970-01-01
  • 2014-05-23
  • 2016-11-06
  • 2014-06-29
  • 2012-07-05
  • 2023-04-04
相关资源
最近更新 更多