PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

DataGrid AllowSort Issue

 
 
Prasanna Ekanayake
Guest
Posts: n/a
 
      30th Jan 2004
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.












 
Reply With Quote
 
 
 
 
Dmitriy Lapshin [C# / .NET MVP]
Guest
Posts: n/a
 
      30th Jan 2004
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.
>
>
>
>
>
>
>
>
>
>
>
>


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: DataGrid Issue Gary Blakely Microsoft ASP .NET 0 7th Oct 2005 01:08 AM
DataGrid Issue Dave Hagerich Microsoft ASP .NET 0 3rd Oct 2005 06:45 PM
Datagrid Issue Sean Microsoft Dot NET Framework Forms 2 18th May 2005 05:34 AM
AllowSort in Datagrid Sam Microsoft VB .NET 2 25th Feb 2005 05:48 PM
Same DataGrid Issue Arvind P Rangan Microsoft ASP .NET 2 1st Mar 2004 02:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:13 PM.