0

I'm receiving the following exception when I try to use a custom format in my DateTimePicker :

"The string was not recognized as a valid DateTime."

I'm using the following snippet :

  dtpSystemAdjustmentDate.Format = DateTimePickerFormat.Custom;
  dtpSystemAdjustmentDate.CustomFormat = "mm.dd.yyyy hh:mm:ss";

I've found documentation on the Microsoft help pages : http://msdn.microsoft.com/en-us/library/aa983603%28v=vs.71%29.aspx

I Tried this snippet :

    // C#
    dateTimePicker1.CustomFormat = "'Today is:' hh:mm:ss dddd MMMM dd, yyyy";

I'm receiving also an exception, complaining about "Today" being a keyword that is not recognized.

I suspect something related to culture (my current Culture is fr-CH) but I can't find a way to make it work... Any idea ?

Andy M
  • 5,945
  • 7
  • 51
  • 96
  • On which line you get this _string was not recognized_ exception? Can you please show all code? And what is your `CurrentCulture`? – Soner Gönül Sep 23 '14 at 06:48
  • Any help by reading this http://stackoverflow.com/questions/241964/how-to-change-culture-to-a-datetimepicker-or-calendar-control-in-net ? – Pavenhimself Sep 23 '14 at 07:10
  • I'm not receiving the exception when starting my application with break points on those lines... – Andy M Sep 23 '14 at 07:43
  • My currentCulture is fr-CH. – Andy M Sep 23 '14 at 07:46
  • Commenting the first two code lines of my question removes the exception... So the exception should be around there... I also tried to invert the lines to put the CustomFormat first... Doesn't change the behavior... – Andy M Sep 23 '14 at 07:53
  • I've found my problem. We're inheriting one of our Form classes that is in charge of translating all the controls in the form. Unfortunately, it handles pretty badly the translation of DateTimePicker. – Andy M Sep 23 '14 at 08:28

1 Answers1

0

My problem wasn't related to .Net or C#.

I tried a blank project, using the same code and it worked.

I was inheriting a subclass of Form that is in charge of translating the Controls within the form. Unfortunately, something is messing up the text content of my DateTimePicker.

My previous lines were correct.

Andy M
  • 5,945
  • 7
  • 51
  • 96