multi column sorting of datagrid view:
I have a datagridview in a windows form with 3 columns: Serial numb开发者_如何学Cer, Name and Date-Time.
The Name column will always have either of the two values: "name1" or "name2".
I need to sort these columns such that the grid displays all the rows with name values in a specific order (first display all the "name1" rows and then all the "name2" rows). Within the "name1" rows, I want the rows to be sorted by the Date-Time. Please note programmatically, all the 3 columns are strings.
For example, if I have the rows:
01 |Name1 | 2010-05-05 10:00 PM
02 |Name2 | 2010-05-02 08:00 AM 03 |Name2 | 2010-05-01 08:00 AM 04 |Name1 | 2010-05-01 11:00 AM 05 |Name1 | 2010-05-04 07:00 AMneeds to be sorted as
04 |Name1 | 2010-05-01 11:00 AM
05 |Name1 | 2010-05-04 07:00 AM 01 |Name1 | 2010-05-05 10:00 PM 03 |Name2 | 2010-05-01 08:00 AM 02 |Name2 | 2010-05-02 08:00 AMI am not sure how to go about using the below:
myGrid.Sort(.....,ListSortDirection.Ascending)
Define your sort expression as string that contains a comma-separated list of field names. Have a look for example here http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sort.aspx
精彩评论