简体   繁体   English

datagrid视图的多列排序:

[英]multi column sorting of datagrid view:

I have a datagridview in a windows form with 3 columns: Serial number, Name and Date-Time. 我在Windows窗体中有3列的datagridview:序列号,名称和日期时间。

The Name column will always have either of the two values: "name1" or "name2". “名称”列将始终具有以下两个值之一:“ name1”或“ 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). 我需要对这些列进行排序,以便网格以特定顺序显示所有具有名称值的行(首先显示所有“ name1”行,然后显示所有“ name2”行)。 Within the "name1" rows, I want the rows to be sorted by the Date-Time. 在“ name1”行中,我希望按日期时间对行进行排序。 Please note programmatically, all the 3 columns are strings. 请以编程方式注意,所有3列都是字符串。

For example, if I have the rows: 例如,如果我有以下行:

01 |Name1 | 01 |名称1 | 2010-05-05 10:00 PM 2010-05-05 10:00 PM
02 |Name2 | 02 |名称2 | 2010-05-02 08:00 AM 2010-05-02 08:00 AM
03 |Name2 | 03 |名称2 | 2010-05-01 08:00 AM 2010-05-01 08:00 AM
04 |Name1 | 04 |名称1 | 2010-05-01 11:00 AM 2010-05-01 11:00 AM
05 |Name1 | 05 |名称1 | 2010-05-04 07:00 AM 2010-05-04 07:00 AM

needs to be sorted as 需要排序为

04 |Name1 | 04 |名称1 | 2010-05-01 11:00 AM 2010-05-01 11:00 AM
05 |Name1 | 05 |名称1 | 2010-05-04 07:00 AM 2010-05-04 07:00 AM
01 |Name1 | 01 |名称1 | 2010-05-05 10:00 PM 2010-05-05 10:00 PM
03 |Name2 | 03 |名称2 | 2010-05-01 08:00 AM 2010-05-01 08:00 AM
02 |Name2 | 02 |名称2 | 2010-05-02 08:00 AM 2010-05-02 08:00 AM

I 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 在这里查看示例http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sort.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM