views:

152

answers:

1

I've got a datagridview 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?

+1  A: 

On design, in the Edit Columns dialog of the DataGridView:

  1. Search for property DefaultCellStyle, and open this dialog;
  2. Search for property Format and choose Date format;
  3. Choose your favorite format.
Will Marcouiller
If I do that, the changes definitely take hold and that's fine, but that's not the outcome I want. I don't want to apply any specific format, I want it to take Window's Default format. Everything else does this just fine, but not this control.
Nick
I know, that is a bug somehow or a lack, if I may say so. I used to set the `DefaultCellStyle` property of a *DateTime* column *OnFormLoad*.
Will Marcouiller
Or you could simply format your bound DateTime property on hte getter, wouldn't work?
Will Marcouiller
I ended up manually setting the format for default cell style on form load to columnOjbect.DefaultCellStyle.Format = System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern + " " + System.Globalization.DateTimeFormatInfo.CurrentInfo.LongTimePattern;
Nick