求助!!!
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
string s;
if (e.ColumnIndex==7)
{
s = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
if (s == "√")
{
s = "";
}
else
{
s = "√";
}
dataGridView1.Rows[e.RowIndex].Cells[7].Value = s;
}
if (e.ColumnIndex == 8)
{
s = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString();
if (s == "√")
{
s = "";
}
else
{
s = "√";
}
dataGridView1.Rows[e.RowIndex].Cells[8].Value = s;
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
当s = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
的时候可以执行。当 s = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString();
的时候报错,报错内容:未将对象引用设置到对象的实例。
请问该怎么解决呢??本人新手