Hi el_sid,
Thanks for your posting!!
Can you show us where is the DataGrid.Select() called after column sorting?
Normally, if we explicitly call this method in DataGrid_MouseUp or
CurrencyManager.CurrentChanged event, both will have no effect. The cause
is what you suspect: the actual dataview sorting occurs after these 2
events.
For this issue, we should inherit from DataGrid class, then in the child
class override its OnMouseUp method. At last, we should place the
DataGrid.Select() method calling after the base.OnMouseUp (e) call. Sample
code lists below:
public class MyDataGrid : System.Windows.Forms.DataGrid
{
private System.ComponentModel.Container components = null;
public MyDataGrid()
{
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp (e);
System.Drawing.Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hti = this.HitTest(pt);
if(hti.Type == DataGrid.HitTestType.Cell)
{
this.CurrentCell = new DataGridCell(hti.Row, hti.Column);
this.Select(hti.Row);
}
if(hti.Type == DataGrid.HitTestType.ColumnHeader && hti.Column == 1)
{
this.Select(this.CurrentRowIndex);
}
}
private void InitializeComponent()
{
this.Name = "MyDataGrid";
}
}
This works well on my side.
Addtionally, I am not sure if you want to select the original selected row,
or the new sorted row in CurrentRowIndex. Normally, DataGrid will sort the
underlying dataview, and lose track of the original selected row. So if you
want to keep track of the original selected row index after sorting. I
think you may follow the below program logic:
1) To override the grid's OnMouseDown protected method to trap clicks on
column headers (the HitTest method can be used to determine where exactly
the click occured).
2) Store the primary key of the current row in a private variable
3) In the OnMouseUp event, after calling base.OnMouseUp(), look up the
stored primary key value and select the appropriate row in the grid.
Hope this helps you.
=========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
el_sid - 30 Mar 2005 13:47 GMT
With a couple of modifications that worked.
Thanks
> Hi el_sid,
>
[quoted text clipped - 77 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 31 Mar 2005 04:33 GMT
Hi el_sid,
Oh, I am glad my reply makes sense to you. If you need further help, please
feel free to tell me, I will work with you. Thanks
Best regards,
Jeffrey Tan
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.