Hi,
The only working way I am aware of is looking up the row by the primary key.
That is, every time the user selects a row, you remember its primary key,
and when the sort order changes, you look up the remembered key value in the
DataView available through the CurrencyManager.List property and set the
CurrencyManager's Position property to the index of the found row.
The CurrencyManager instance can be obtained through
CurrencyManager cm = (CurrencyManager)this.BindingContext[grid.DataSource,
grid.DataMember];
--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Prasanna Ekanayake" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
>
>
> How can I get the DataRow that the user selected/clicked in an AllowSort
> enabled DataGrid? Given below is what I'm currently trying to do to
achieve
> it.
>
>
>
> I have a DataTable that is the DataSource to my DataGrid. The DataTable
> contains all data from my SalesRep table which contains the following
> columns.
>
> UID - Identity Column
>
> ID - UserID [Eg: BD00001]
>
> FirstName
>
> MiddleInitials
>
> LastName
>
> Address
>
> Phone
>
> Fax
>
> Email
>
>
>
> In the DataGrid all columns are displayed EXCLUDING the UID column. I have
> enable AllowSort. Before sorting the DataGrid (by clicking the Column
> header), I can get the UID of the selected/clicked row.
>
>
>
> MessageBox.Show( ( (DataTable) cdg
> cdgSalesRep.DataSource).Rows[cdgSalesRep.CurrentRowIndex][0].ToString() );
>
>
>
> But soon as the DataGrid is sorted (by clicking the Column header), the
> values return by the above statement is wrong.
>
>
>
> If someone could point out what I'm doing wrong it would be a great help.
> What I really want to do is to retrieve the DataRow that the user
> selected/clicked.
>
>
>
> Thanks in Advance!
>
>
>
> Prasanna.
>
>
>
>
>
>
>
>
>
>
>
>