日期:2014-05-18  浏览次数:20782 次

怎么判断dataGridView 中是否有数据?


  我试过2个 都不行。。。。。。
  1:dataGridView1.CurrentRow.Index != -1 不行。。。。
  2:dataGridView1.Rows.Count>0 不行。。。。

  求有效的方法。。。谢谢!!!

------解决方案--------------------
直接数据库判断不行吗
------解决方案--------------------
dataGridView1.DataSource as DataTable
判断数据源
dataGridView1.Rows.Count
------解决方案--------------------
试试这个
if (dataGridView1.Rows.Count == 0)
{
MessageBox.Show("没有数据!");
}
else
{
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
------解决方案--------------------
提个问题啊:如果数据源有记录,但把dataGridView中的Row都隐藏起来,这样算有数据还是没有数据呢