我在 DataGridView 的列中有一个复选框。现在我遇到了一个异常,因为没有选中复选框。我不知道如何处理它?
private void uncheckGrid(ref DataGridView dgv, int index)
{
try
{
foreach (DataGridViewRow row in dgv.Rows)
{
DataGridViewCheckBoxCell check = row.Cells[1] as DataGridViewCheckBoxCell;
if (check.Value != null) // throw an exception here.
{
if ((bool)check.Value)
{
Int32 intVal = Convert.ToInt32(row.Cells[0].Value);
if (intVal == index)
{
check.Value = false;
}
}
}
}
谢谢。