以编程方式取消选中datagridview中的checkboxcolumn

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

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

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

但那只是一个吸气剂。

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

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

但这不会影响FormattedValue。

我怎么解决这个问题?

你做某事 喜欢:

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

你只是了转换为正确的类型,一般的DataGridViewCell不知道它的值类型。

没有检查但你可以尝试;

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

它的类型可能不同。 只需调试并将其投射到它的位置即可。

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

尝试这种程度的东西。

 ((DataGridViewCheckBoxCell)e.Rows[0].Cells[0]).Selected = true 
 foreach (DataGridViewRow dr in dataGridView1.Rows) { dr.Cells[0].Value = true;//sıfırın } 

如果你使用dataGridView1_ContextClick只是为了做“假”datagidviewCheckBox列需要这个代码:

 dataGridView1.CancelEdit(); 

但是如果你需要DataGrid的CheckBoxColumns的所有行:

 private void button1_Click(object sender, EventArgs e) { foreach (DataGridViewRow r in dataGridView1.Rows) { r.Cells["statusBox"].Value = true; } } 

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

 foreach ( GridViewRow row in myGridView ) { CheckBox checkBox = ( CheckBox ) row.FindControl( "myCheckBox" ); checkbox.Checked = false; } 
  foreach (DataGridViewRow row in datagridviewname.Rows) { row.Cells[CheckBoxColumn1_Name].Value = false; }