简体   繁体   English

如何将行添加到特定等级,DataViewGrid,C#

[英]How to add row to specific rank, DataViewGrid, C#

I have DataViewGrid with three columns. 我有三列的DataViewGrid

| ID | NAME | DATE |

DATE is type of DateTime . DATE是DateTime类型。

I want to add rows so that they are ordered by date. 我想添加行,以便按日期对其进行排序。 How? 怎么样?

Example: 例:

1 JACOB 27.5.2015 23:15.10
6 PETER 27.5.2015 23.16.10
9 PETER 27.5.2015 23.16.41

Data are addet by method: 数据按方法添加:

public void add(int id, String name, DateTime dateTime)

you could use the default sort method of the DataGridView. 您可以使用DataGridView的默认排序方法。 First, you need to make sure that all cells in this row have the same ValueType (set the ValueType through eg dataGridView1[0,2].ValueType=typeof(DateTime);) 首先,您需要确保该行中的所有单元格都具有相同的ValueType(例如,通过dataGridView1[0,2].ValueType=typeof(DateTime);)设置ValueType dataGridView1[0,2].ValueType=typeof(DateTime);)

Then you need to make the Column "sortable", by setting dataGridView.Columns[2].SortMode=DataGridViewColumnSortMode.Automatic; 然后,需要通过设置dataGridView.Columns[2].SortMode=DataGridViewColumnSortMode.Automatic;来使列“可排序” dataGridView.Columns[2].SortMode=DataGridViewColumnSortMode.Automatic;

And through following code you can sort your rows by column ascending dataGridView1.Sort(dataGridView1.Columns[2], ListSortDirection.Ascending); 通过以下代码,您可以按列升序对行进行排序dataGridView1.Sort(dataGridView1.Columns[2], ListSortDirection.Ascending);

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

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