sorting in datagrid, and retrieving selections from data source

R

Rushabh Dadbhawala

Problem:
I am fetching data from the database, storing it in a
dataSet, and binding it with a Data Grid. The DataGrid
controls allows sorting. The problem is that when the data
is sorted on one of the columns in the Data Grid, and I
then try to retrieve the selected row using
the "SelectedRowIndex", I get the row as per the original
order of data.
Eg: If the order of rows is: C - A - B, which after
sorting becomes A - B - C. Now, if I select the 3rd row,
and try to fetch all the cells for this row, I get the
row "B", and not the row "C".

For the time being, I have disabled sorting from the Data
Grid, and am retrieving data in the sorted order of the
key. But sorting has to be available in the control.

Any ideas ??

Thanks,
RD.
 
N

Nicholas Paldino [.NET/C# MVP]

RD,

When you bind to a datatable using the data grid, it is actually binding
to the DataView exposed by the DefaultView property. If you use the
selected row index on the view, then you will get the correct row that
corresponds to the sorted data grid.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top