views:

34

answers:

1

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)
+1  A: 

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

Jull
he is asking for DataGridView (WinForms), not GridView (WebForms)
Hao