I've got a datagri开发者_运维问答dview that is hooked up to a bindingsource on my main form. One of the columns and datamembers in the bindingsource is a DateTime object. When the datagridview shows this item it doesn't use Window's default region settings for displaying datetime.
The weird thing is, I can access this same DateTime object and print it to a text box, or even pass it off to another form with another datagridview and binding source and it actually shows up properly in that table.
So then, why does the datagridview on my main form not use the regional date/time settings when converting the DateTime object to a string?
I've checked that there was no special formatting applied to the datagridview and so I'm running out of ideas to check.
Do you guys know if there is any super secret way to get a datagridview to follow system regional format rules or not?
Also, since I highly doubt that I did something different with this datagridview vs the others in my application, the next potential area for issue could be on application load: Perhaps since this comes up when the application loads, it's not getting the same cultureUI settings as the other datagridviews?
Update I've tried adding another column to the datagrid view and hooking it up to the same data property (datetime) and I get the same result. So something about how entire datagridview, or how it was created is stopping the "ToString" from using the default regional settings.
Any Help?
On design, in the Edit Columns
dialog of the DataGridView:
- Search for property
DefaultCellStyle
, and open this dialog; - Search for property
Format
and choose Date format; - Choose your favorite format.
精彩评论