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#?
Look at the
sortmethod of theDataGridView. 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:This link shows how to sort the
DataGridViewonce it is bound to your data source.