我用了两个dataGrid来显示数据库中的同一个表的不同字段的记录,现在想搞成当点击dataGrid1的某一行时,dataGrid2的相应一行也被选中了,但是我在dataGrid1的CurrentCellChanged事件中写
this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
this.dataGrid2.Select(this.dataGrid2.CurrentRowIndex);这样做好像不行啊,当选中dataGrid1的第一条记录时dataGrid2也选中了第一条记录,但是当选中dataGrid1的第二条记录的时候,dataGrid2也选中了第二条,问题就是出在这里,dataGrid2的第一条记录还是显示为选定的,大家有什么办法可以去掉第一条记录的选择的?????

解决方案 »

  1.   

    dataGrid2.SelectIndex = -1;
    dataGrid2.selectIndex = this.dataGrid1.CurrentRowIndex;
      

  2.   

    少写了两个"ed"
    dataGrid2.SelectedIndex = -1;
    dataGrid2.selectedIndex = this.dataGrid1.CurrentRowIndex;
      

  3.   

    兄弟,好像没有 SelectedIndex 啊!!!
      

  4.   

    int index = this.dataGrid1.CurrentRowIndex;
    this.dataGrid1.Select(index);
    this.dataGrid2.CurrentRowIndex = index;
      

  5.   

    兄弟,你们这样写其实跟我写的有什么分别啊?还是不行啊,要想取消掉dataGrid2中原来选中的一行啊,我现在就是不知道该如何判断是否选中的行的序号是否与之前选中的相同啊,然后用this.dataGrid2.UnSelect();去掉,你们再帮忙想想吧。其实你们先试试啊
      

  6.   

    你用的是不是DataGrid,我这里明明有SelectedIndex,倒是没有Select()和UnSelect().
      

  7.   

    哦,WinForm和WebForm中的DataGrid不同!