简体   繁体   中英

c# datagridview order rows?

I have a datagridview with a number of columns, one of these is a datetime column. 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? The gridviews datasource is an 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.

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).

If your BingingList is bound to the DataGridView you can sort.

As far as I know, sorting is not supported for XML data sources. I think your best approach will be to first load the XmlDocument into a dataset and bind that to the grid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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