Click here to Skip to main content
15,905,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
DGV assumes the column is a text string even though it is set as a Datetime column


The defaults cell format is "DataGridViewCellStyle { Format=dd-MMM-yy, Alignment=MiddleCenter }"

What I have tried:

Changing date text format.
The DGV does not convert the date sting properly
Posted
Updated 15-Mar-20 5:48am
Comments
Richard MacCutchan 15-Mar-20 10:33am    
According to the documentation it should sort on Values not formatted output.

1 solution

If you pass it a string, it will treat it as a string: it won;t try to convert it to a DateTime value for you.

So check exactly what you are passing it, and use TryParse or TryParseExact to convert it before it gets to the DGV. A format string will only have an effect on DateTime values, and sorting will be on the actual type of the value - and a string comparison is character by character, it doesn't "know" about dates unless they are actual DateTime values.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900