简体   繁体   English

c #datagridview命令行?

[英]c# datagridview order rows?

I have a datagridview with a number of columns, one of these is a datetime column. 我有一个包含多个列的datagridview,其中一列是datetime列。 I want to display the rows from most recent downwards. 我想显示最近向下的行。 eg Today Yesterday The Day Before Yesterday etc. 例如今天昨天昨天前一天等

Is it possible to do this with the datagridview? 是否可以使用datagridview执行此操作? The gridviews datasource is an xmldocument....... gridviews数据源是一个xmldocument .......

help appreciated greatly. 非常感谢。

Regards, 问候,

 this.dataGridView1.Sort(dataGridView1.Columns["DateTime"], ListSortDirection.Ascending);

What is your datasource? 你的数据源是什么? You have to have a datasource that supports sorting. 您必须拥有支持排序的数据源。

eg a DataTable. 例如DataTable。

If you have a List you can't sort by default. 如果您有列表,则默认情况下无法排序。 In theory you need your on class that inherits from BindingList and implements IBindingList (inheritance from BindingList is not nessacary, but makes it a bit easier). 从理论上讲,您需要继承自BindingList的类,并实现IBindingList(从BindingList继承并不是必需的,但会让它更容易一些)。

If your BingingList is bound to the DataGridView you can sort. 如果你的BingingList绑定到DataGridView,你可以排序。

As far as I know, sorting is not supported for XML data sources. 据我所知,XML数据源不支持排序。 I think your best approach will be to first load the XmlDocument into a dataset and bind that to the grid. 我认为您最好的方法是首先将XmlDocument加载到数据集中并将其绑定到网格。

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

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