datagridview无数据显示问题处理

来源:互联网 发布:威斯特伐利亚和约知乎 编辑:程序博客网 时间:2024/06/06 15:00

1.if (dataGridView1.Rows.Count < 1) return;
 int index = dataGridView1.CurrentRow.Index;     //获取当前选中行索引号
dataGridView1.Rows[index].Selected = true;      //加亮显示
string Inven_No = this.dataGridView1["InventoryNo", index].Value.ToString();
2.if (ds.Tables["tb"].Rows.Count == 0)
   {  MessageBox.Show("没有符合条件的数据"); }
3.
    OracleDataAdapter da = new OracleDataAdapter(strSQL, conn);
    ds = new DataSet();
    da.Fill(ds);
     if (ds.Tables[0].Rows.Count == 0)
     {
        MessageBox.Show("没有符合条件的数据");
      }
    da.Dispose();
    this.bindingSource1.DataSource = ds.Tables[0];
    this.bindingNavigator1.BindingSource = bindingSource1;
    this.dataGridView1.DataSource = bindingSource1;
    this.dataGridView1.DefaultCellStyle.SelectionBackColor = Color.LightSteelBlue;
    this.dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black;

原创粉丝点击