如何以编程方式取消选中 datagridview 中 DataGridViewCheckboxColumn 中的所有行?
我可以使用获得复选框的正确值
(bool)row.Cells[CheckBoxColumn.Index].FormattedValue
但这只是一个吸气剂。
我尝试使用设置单元格的值
(bool)row.Cells[CheckBoxColumn.Index].value = false
但这不会影响 FormattedValue。
我该如何解决这个问题?
如何以编程方式取消选中 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不知道它的值类型。
您是否尝试过将复选框列中的第一个控件转换为复选框,然后将“已选中”设置为 true?
尝试到这种程度。
((DataGridViewCheckBoxCell)e.Rows[0].Cells[0]).Selected = true
没有检查,但你可以试试;
CheckBox cb = (row.Cells[CheckBoxColumn.Index].Controls[0] as CheckBox);
if(cb != null)
{
cb.Checked = false;
}
它的类型可能不同。只需调试并将其转换为它的样子。
foreach (DataGridViewRow dr in dataGridView1.Rows)
{
dr.Cells[0].Value = true;//sıfırın
}
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;
}
}
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!
you should just use YourDataGridview.EndEdit() after checking.
(row.Cells[CheckBoxColumn.Index] as DataGridViewCheckBoxCell).value = false;
YourDataGridview.EndEdit();
循环遍历每一行网格视图并使用查找控制方法:
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;
}