我在一个窗口中添加了两个datagriview,其中datagriview1用来显示表1(学号,课程,成绩),datagriview2用来显示表2(学号,学生姓名,家庭住址)。请问怎么在我单击datagriview1中某行时,datagriview2会显示该学号的信息。

解决方案 »

  1.   

    celldouclick  
    你可以获得该条信息的行索引 e.RowIndexint rowIndex = e.RowIndex;
    string strColumnValue = dataGridView1.SelectedRows[0].Cells["ColumnName"].Value.ToString();//获取选择列中,ColumnName列的值。
    doSomething For Update the other datagriview
      

  2.   

    datagriview1添加一个模板列,里里面放一个Button,写Button的事件。
      

  3.   

     int rowindex = this.dataGridView1.CurrentRow.Index; //获取选中的行
     int id = int.Parse(this.dataGridView1[0, rowindex].Value.ToString());//获取学号
     dataGridView2.DataSource=(select * from table2 where id="+id+");