tryCurrencyManager cm = (CurrencyManager)BindingContext[dataGrid1.DataSource, dataGrid1.DataMember];dataGrid1.CurrentRowIndex = cm.Position;

解决方案 »

  1.   

    sorry, I think I misunderstood your question, here is what you should do, before sorting:CurrencyManager cm = (CurrencyManager)BindingContext[dataGrid1.DataSource, dataGrid1.DataMember];
    DataRow dr = ((DataRowView)cm.Current).Row; after sorting, find the position of this DataRow, something likeint n=0;
    DataView dtView = (DataView)dataGrid1.DataSource;
    for (int i=0; i < dtView.Count;i++)
      if (((DataRowView)dtView[i]).Row == dr)
    n=i;dataGrid1.CurrentRowIndex = n;
      

  2.   

    在DataGrid鼠标单击和双击事件里加入下面的代码也可以办到,Point p=this.dataGrid1.PointToClient(Cursor.Position);
    if (this.dataGrid1.HitTest(p).Type==DataGrid.HitTestType.ColumnHeader)
    {
    BindingManagerBase bm= this.BindingContext[this.dataGrid1.DataSource,this.dataGrid1.DataMember];
    this.dataGrid1.CurrentRowIndex=bm.Count-this.dataGrid1.CurrentRowIndex-1;
    }
      

  3.   

    请问 saucer(思归) :
    有没有办法不用遍历?
    to: dy_2000_abc(芝麻开门) 
    你的办法,对其中一列排序过之后,再次排序该列,是可以的,但是其他情况不灵啊。