Some good info in the first and last references but what I would like to do is sort the arrays themselves.
Main Topics
Browse All TopicsI have an application that contains a datagridview. The datagridview displays the values of three arrays in three columns.
Ex. Unsorted Arrays
Ts() Ps() Cs()
A Reg 2.50
A Mid 2.60
B Reg 2.52
B Pre 2.72
A Pre 2.73
I would first like to sort the arrays such that Ts() is sorted A's first. I would then like to sort them so that once the A's are sorted the Ps's are Ordered Reg,Mid, Pre
The sorted array should look like....
A Reg 2.50
A Mid 2.60
A Pre 2.73
B Reg 2.52
B Pre 2.72
Thank You!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Based on your example sort it looks more like it should sort by Ts() then Cs() because you posted this:
A Reg 2.50
A Mid 2.60
A Pre 2.73
The Ps() are not sorted before the Cs() as in:
A Mid 2.60
A Pre 2.73
A Reg 2.50
Why are you using separate arrays? If you make a DataSet/DataTable out of the values then you can sort on multiple columns quite easily as Dhaest has shown in his links.
To sort multiple separate arrays you have to "sync" them and move the values in all three arrays as you sort...quite messy!
The values actually come into the application in a dataset but there is quite a bit of math that takes place to get the values in Cs(). Also three of the Ps() ,Cost() elements are used to create three additional Ps(),Cs() elements that do not exist in the original dataset. I would have loved to have had a singular dataset to manipulate but I could never come up with a simple and clean method to do so. I suppose I could eliminate all this array sorting by creating a new dataset/datatable after all the manipulation has taken place.
"I suppose I could eliminate all this array sorting by creating a new dataset/datatable after all the manipulation has taken place."
That would be my recommendation.
There isn't any built-in method to sort multiple arrays as "one unit" so you'd have to implement your own sorting algorithm and manually swap all the indexes in the related arrays to keep them in sync.
It's possible if you really want to see it.
I have accomplished the task by sorting the arrays. I think that had the code design been a little different futher upstream it would have made much more sense to do this via datatable. While the sorting method is Im certain not the most efficient, the number of values sorted is quite small and therefore has a negligable impact on performance.
Business Accounts
Answer for Membership
by: DhaestPosted on 2009-11-03 at 23:55:03ID: 25737230
Sort multiple columns of Windows Datagridview m/resource s/5172-Sor t-multiple - columns-W indows-Dat agridview. aspx
/KB/grid/m ulticolumn _sort.aspx
en-us/libr ary/ms1716 07.aspx
http://www.dotnetspider.co
DataGridView Multi-column Sort
http://www.codeproject.com
Sorting Data in the Windows Forms DataGridView Control
http://msdn.microsoft.com/