Reputation: 4434
I'm using 2010 Express and I have an array arrStudents, where each element contains the students' names (arrStudents(0).Name) and ages (arrStudents(0).Age). I would like to present the contents of my array so that the user can see it in a 2 column by 100 row grid, like in Excel, where the Names are displayed in Column A and Ages displayed on Column B.
Then, the user can double click somewhere so that it sorts Column A alphabetically, or sorts B by ascending age. Then, if you double click again it does the reverse and sorts column A alphabetically by descending order and column B by age in descending order. What's the best way to come as close to this as possible in C#?
Upvotes: 0
Views: 526
Reputation: 21897
Look at thesort
method of the DataGridView
. You pass it which column to sort by, and either ascending or descending order.
To bind data to the DataGridView
, you set the datasource of the control to your array:
myDataGridView.DataSource = myArray;
This link shows how to sort the DataGridView
once it is bound to your data source.
Upvotes: 1