multicolumn sorting of WinForms DataGridView

Posted by Bi on Stack Overflow See other posts from Stack Overflow or by Bi
Published on 2010-05-11T17:42:33Z Indexed on 2010/05/12 0:34 UTC
Read the original article Hit count: 594

Filed under:
|

I have a DataGridView in a windows form with 3 columns: Serial number, 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 AM

needs 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 AM

I am not sure how to go about using the below:

myGrid.Sort(.....,ListSortDirection.Ascending)

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms