我想点击按钮
检查Gridview程序中的复选框答案 0 :(得分:1)
如果您知道单元格的位置,则可以将其设置为
datagridview1[0,2].Value = true;// this should be a checkboxcolumn
OR
datagridview1["chkboxcolumnName",2].Value = true;
这将导致检查该特定单元格的复选框。
希望这就是您的意思,请编辑问题以获取更多详细信息。
答案 1 :(得分:0)
以这种方式尝试(通过订阅两个事件):
void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dataGridView1.IsCurrentCellDirty)
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
private void dataGridView1_CellValueChanged(object obj, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1) //compare to checkBox column index
{
DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)dataGridView1[e.ColumnIndex, e.RowIndex];
if (!DBNull.Value.Equals(cbx.Value) && (bool)cbx.Value == true)
{
//checkBox is checked - do the code in here!
}
else
{
//if checkBox is NOT checked (unchecked)
}
}
}
答案 2 :(得分:0)
这对我有用:
for (int i = 0; i < dataGridView1.RowCount - 1; i++)
{
dataGridView1.Rows[i].DataGridView[0, i].Value = false;
}