简体   繁体   English

数据绑定的DataGridView无法正确排序日期

[英]Databound DataGridView not sorting date correctly

My DataGridView is not sorting my date column correclty and it doesn't seem to be sorting it by String either. 我的DataGridView没有对日期列的正确性进行排序,而且似乎也没有按String对其进行排序。 The column is bound to a date property, all is done using the designer. 该列绑定到date属性,所有操作均使用设计器完成。

The set which I'm viewing it on is 424 entries long, there should be two entries for each date and they should be next to each other (regardless if sorting by date or string) 我正在查看的集合长424个条目,每个日期应有两个条目,并且它们应该彼此相邻(无论按日期或字符串排序)

The last few dozen entries are sorted correctly but the initial entries are not. 最后几十个条目已正确排序,但初始条目未正确排序。

Initially every second entry at the start is correct. 最初,开始时每隔第二个条目都是正确的。 Here is an extract if some of the sorting it does. 这是一些分类的摘录。

(The beginning of the sorted grid is on the left, and the end of grid is on the right) (已排序的网格的开始在左侧,而网格的结束在右侧)

替代文字

I've no idea what is causing this, or how to fix it. 我不知道是什么原因引起的,或者如何解决。 Any ideas would be greatly appreciated! 任何想法将不胜感激!

Thanks! 谢谢!

Use the SQL you called to get the data to also ORDER BY date DESC or ASC. 使用调用的SQL来将数据也传递到ORDER BY日期DESC或ASC。 This will give you the SQL servers adaptation of the date order. 这将使您的SQL Server适应日期顺序。

An example would be: 一个例子是:

SELECT Name, Salary
FROM Employee
ORDER BY Start_Date DESC

This way you are not relying on the grid to accurately sort dates. 这样,您就不必依赖网格来准确地对日期进行排序。 Also check that there are no date locale settings in your grid control. 还要检查您的网格控件中是否没有日期区域设置。 It could be the locale is set to another country. 可能是语言环境设置为另一个国家。

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

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