3

如何以编程方式取消选中 datagridview 中 DataGridViewCheckboxColumn 中的所有行?

我可以使用获得复选框的正确值

(bool)row.Cells[CheckBoxColumn.Index].FormattedValue

但这只是一个吸气剂。

我尝试使用设置单元格的值

(bool)row.Cells[CheckBoxColumn.Index].value = false

但这不会影响 FormattedValue。

我该如何解决这个问题?

4

9 回答 9

2

你做某事。像:

(row.Cells[CheckBoxColumn.Index] as DataGridViewCheckBoxCell).value = false;

您只是忘记转换为正确的类型,泛型DataGridViewCell不知道它的值类型。

于 2011-01-18T15:41:39.013 回答
1

您是否尝试过将复选框列中的第一个控件转换为复选框,然后将“已选中”设置为 true?

尝试到这种程度。

((DataGridViewCheckBoxCell)e.Rows[0].Cells[0]).Selected = true
于 2011-01-18T14:46:15.840 回答
0

没有检查,但你可以试试;

CheckBox cb = (row.Cells[CheckBoxColumn.Index].Controls[0] as CheckBox);
if(cb != null)
{
    cb.Checked = false;
}

它的类型可能不同。只需调试并将其转换为它的样子。

于 2011-01-18T15:13:29.647 回答
0
foreach (DataGridViewRow dr in dataGridView1.Rows)
{
  dr.Cells[0].Value = true;//sıfırın
}
于 2012-01-17T08:09:25.990 回答
0

If you use dataGridView1_ContextClick just for do "false" datagidviewCheckBox Column need this Code :

dataGridView1.CancelEdit();

but if you need all rows of CheckBoxColumns of DataGrid :

private void button1_Click(object sender, EventArgs e)
{
    foreach (DataGridViewRow r in dataGridView1.Rows)
    {
        r.Cells["statusBox"].Value = true;
    }
}
于 2016-03-05T16:45:52.093 回答
0

Depending on what you wish to do

If it is about the selected row, then you can:

DataGridViewRow row = dataGridViewName.CurrentRow;

//This will assign the opposite value of the Cell Content
row.Cells["ColumnName"].Value = !Convert.ToBoolean(row.Cells["ColumnName"].Value);

However if you wish to do it for the whole DataGridView table then:

    foreach (DataGridViewRow row in dataGridViewName.Rows)

   {
        //This will assign the opposite value of the Cell Content
        row.Cells["ColumnName"].Value = !Convert.ToBoolean(row.Cells["ColumnName"].Value);
   }

Whatever suites you. Keep it up!

于 2021-03-19T09:56:41.643 回答
0

you should just use YourDataGridview.EndEdit() after checking.

(row.Cells[CheckBoxColumn.Index] as DataGridViewCheckBoxCell).value = false;
YourDataGridview.EndEdit();
于 2021-10-18T05:16:45.903 回答
-1

循环遍历每一行网格视图并使用查找控制方法:

foreach ( GridViewRow row in myGridView )
{
     CheckBox checkBox = ( CheckBox ) row.FindControl( "myCheckBox" );
     checkbox.Checked = false;
}
于 2011-01-18T15:19:12.057 回答
-1
 foreach (DataGridViewRow row in datagridviewname.Rows)

  {
    row.Cells[CheckBoxColumn1_Name].Value = false;
  }
于 2013-07-12T11:01:20.330 回答