当单元格离开时,我正在尝试对单元格的内容进行一些文本处理。我有以下代码,但是当我在单元格中输入任何文本然后离开时出现以下异常。
An unhandled exception of type 'System.NullReferenceException' occurred in Program.exe
Additional information: Object reference not set to an instance of an object.
如果我打破并将鼠标悬停在它上面.value
确实为空,但我已将数据输入到单元格中!那么给了什么?
private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 3)
{
string entry = "";
MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
MakeTextFeet(entry);
}
if (e.ColumnIndex == 4)
{
string entry = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
MakeTextFeet(entry);
}
}