Sort Dataset Based on Connected Datagridview sort


I have a DataGridView that I use for a search result form where the user double clicks a data row to open the row id ITEMS form. The users are able to sort the DataGridView by any column.

I would like to pass the dataset connected to the DataGridView to the ITEM form but the dataset needs to be in the same sort order as the DataGridView on the search result form.

Is this possible without looping through the entire DataGridView?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
First of all, you cannot sort a DataSet. You can sort a DataTable, but not a DataSet, which is a collection of tables. You might want to read the article I wrote on the subject.

A DataTable can be filtered and sorted through a DataView object. Once created, the DataView can be used as if it was the DataTable, but does is not sorted in the same order and, if you applied a filter, does not give access to all the data. Changes made in the DataView are made in the DataTable, because the DataView is only a different representation of the original DataTable.

Look at  the official documentation at DataView Class for examples of how to create and use a DataView.

Pass your DataView to your ITEM form.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.