473,324 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

sorting in datagrid, and retrieving selections from data source

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.

Nov 15 '05 #1
1 2247
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rushabh Dadbhawala" <rd*********@yahoo.co.in> wrote in message
news:03****************************@phx.gbl...
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.

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
1
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current...
1
by: David McCormick | last post by:
I have been scouring the message boards before I posted this question hoping to find an answer regarding datagrids and their behaviour after a sort command has been invoked. What I am trying to...
11
by: rkbnair | last post by:
I have created a datagrid in my aspx with the 'AllowSorting' property to true. When clicking on the column header, the page refreshes. However the sorting is not done. Am I missing anything? I...
5
by: I am Sam | last post by:
I have a rather complicated problem I need to sort out and wonder if anyone can assist me. The ingredients: Two DropDownList Controls One DataGrid Purpose of Page:
5
by: DKC | last post by:
Hi, Using VB.NET. I have a datagrid having a strongly typed array of objects as its data source. The data from the array of objects is displayed by means of a table style, which is fine, but...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.