我有一个程序,它从dataGridView中选择的行中获取一个值并将其传递给函数。然而,gridView可能为空或没有选择任何行。
我已经处理了空Grid,但我想知道是否有一种方法可以判断是否选择了任何行。
我尝试了这个:
if (Convert.ToInt32(dataGridView1.Rows.Count) > 0)
{
//It is not empty
}
int c = dataGridView1.SelectedRows.Count(); //this line gives me an error
if (c>0)
{
//there is a row selected
}
你知道我怎么解决这个问题吗?