datagridview 判断查询是否为空

来源:百度知道 编辑:UC知道 时间:2024/06/04 23:39:50
设置了点击dataGridView内容时 textbox会显示某选种记录的某内容
textBox1.Text = Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim();

当dataGridView查询为空时,我点击上面的字段就会出错,
未处理NullReferenceException
怎么处理啊????? 《内容》

try{
点击时间
}
catch(Exceprion e)
{
处理异常
}

dataGridView1.CurrentCell为Nothing。

If Not dataGridView1.CurrentCell Is Nothing Then
textBox1.Text = Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim();
End If

try{
点击时间
}
catch(Exceprion e)
{
处理异常
}
If Not dataGridView1.CurrentCell Is Nothing Then
textBox1.Text = Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim();
End If