我定义的了三个变量:bookid,bookname,zaiguanshu;
我想单击datagridview中的某一行时,将对应行的字段数据传给以上三个变量。如何获得所选行的索引,谢谢!

解决方案 »

  1.   

    双击datagirdview上的cellclick事件
    会出现
      private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    然后接e的参数e.RowIndex就是第几行的索引
    如果你想去取对应值,就打出cell的列数,比如
    string test1=dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
    其中0是第几列,也可以用列名带代替,比如
    string test1=dataGridView1.Rows[e.RowIndex].Cells["申购条件"].Value.ToString();
      

  2.   

    datagridview1.currentRow.Index; 获取行的索引