我动态设置CheckBox
中DataGridView
列中的DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)dataGridRow.Cells["colChk"];
chk.Selected = true;
chk.Value = 1;
列为“已检查”。
我尝试了很多东西。以下是示例代码。 :
{{1}}
答案 0 :(得分:0)
我已经测试了我的情况,它运作正常。
private void AddRow_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Add();
}
private void ChangeCheck_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
if (row.Cells[0].ValueType == typeof(bool))
{
if (row.Cells[0].Value == null)
row.Cells[0].Value = true;
else
row.Cells[0].Value = !(bool)row.Cells[0].Value;
}
}
}
如果DataGridView绑定了DataSouce,我建议你只能从true-> false更改你的属性,如果你需要更多的帮助,请评论我的帖子。