简体   繁体   中英

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. The column is bound to a date property, all is done using the designer.

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)

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. This will give you the SQL servers adaptation of the date order.

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.

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