这是我的代码
           int IdNo;
           DataGridViewRow dr = dataGridView1.CurrentRow;
           IdNo= dr.Cells["ID"].Value;
问题是每次取的值却是下一行的记录而不是本行的记录,请问会是什么问题呢
        

解决方案 »

  1.   

    使用:
    int IdNo = Convert.ToInt32(dataGridView1.CurrentRow[0].Cells["ID"].Value);
      

  2.   


    clandyLee兄弟,有出现以下错误
    错误 3 无法将带 [] 的索引应用于“System.Windows.Forms.DataGridViewRow”类
      

  3.   

    DataGridView绑定了DataTable的话就不用这么麻烦了。
    比如,是这么绑定的。BindingSource bs = new BindingSource();
    bs.DataSource = dataSet1;
    bs.DataMember = "Table";dataGridView1.DataSource = bs;....
    DataRowView drv = (DataRowView)bs.Current;
    int IdNo = int.Parse(drv["ID"].ToString());
      

  4.   

    正解为:
    int IdNo = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["ID"].Value);刚记错了~不好意思!~
      

  5.   

    dataGridView1.SelectedRows为当前选中行的集合,下标由0开始,由上至下.
    dataGridView1.SelectedRows.Count为当前选中行数.
    删除多行使用for循环即可!