Re: DateTimePicker Oddness
First of all I would question why you're assigning Strings to properties of type DateTime. You obviously have Option Strict Off so I'd suggest that you turn that On for a start.
As for the issue, I just tested that scenario and I saw no such behaviour. What configuration are you running on?
Re: DateTimePicker Oddness
Thanks for replying. See environment details below:
OS: Windows Vista Business SP1
IDE: Visual Studio Team System 2008 (Development Edition) - Version 9.0.30729.1 SP
Framework: .NET 3.5 SP1
Re: DateTimePicker Oddness
OK, I tried what you said, and it made no difference. The date format is dd/mm/yyyy. My VB.NET code is below:
Code:
Option Strict On
Public Class Form1
Private Sub Form1_Load(ByVal sender as System.Object, ByVal e as System.EventArgs) Handles MyBase.Load
DateTimePicker1.MinDate = Convert.ToDateTime("01/02/2010")
DateTimePicker1.MaxDate = Convert.ToDateTime("07/02/2010")
End Sub
End Class
Re: DateTimePicker Oddness
Seems like what you have posted last should work.
What is returned from these?
Code:
Console.WriteLine("Current Culture: {0}", _
Thread.CurrentThread.CurrentCulture.EnglishName)
Console.WriteLine("Short date format {0}", _
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortDatePattern)
Console.WriteLine("Date Separator [{0}]", _
Thread.CurrentThread.CurrentUICulture.DateTimeFormat.DateSeparator)
Re: DateTimePicker Oddness
Heya,
Thanks for replying.
The results of running that code was the following:
Current Culture: English (United Kingdom)
Short Date Format: M/d/yyyy
Date Separater: [/]
Regards,
Ross
Re: DateTimePicker Oddness
Quote:
Originally Posted by
dotnetster
Heya,
Thanks for replying.
The results of running that code was the following:
Current Culture: English (United Kingdom)
Short Date Format: M/d/yyyy
Date Separater: [/]
Regards,
Ross
Ok, that should be fine.
Try the following
Code:
Dim MyDate As New Date(2010, 1, 1)
DateTimePicker1.MinDate = MyDate
DateTimePicker1.MaxDate = New Date(2010, 1, 2)
DateTimePicker1.Value = MyDate
Does this still cause problems as mentioned in your first post?
Re: DateTimePicker Oddness
Heya,
I'm not sure what you are trying to achieve in that code.
I need my MinDate to be 01 February 2010, and the MaxDate to be 07 February 2010. In other words, I am finding that the control does not work as expected when you set the MaxDate to be a value less than Today's date.
Regards
Ross
Re: DateTimePicker Oddness
Quote:
Originally Posted by
dotnetster
Heya,
I'm not sure what you are trying to achieve in that code.
I need my MinDate to be 01 February 2010, and the MaxDate to be 07 February 2010. In other words, I am finding that the control does not work as expected when you set the MaxDate to be a value less than Today's date.
Regards
Ross
Well even that works for me. Today is 02/11/2010 and in the code below the max date is less than 02/11/2010.
Code:
Dim MyDate As New Date(2010, 2, 1)
DateTimePicker1.MinDate = New Date(2010, 2, 1)
DateTimePicker1.MaxDate = New Date(2010, 2, 2)
DateTimePicker1.Value = MyDate
No matter what the dates are I do not get what you are getting, all is working fine for me.
Re: DateTimePicker Oddness
Hiya,
Thanks for spending the time working on this.
What do you get when you just have the following:
Code:
DateTimePicker1.MinDate = New Date(2010, 2, 1)
DateTimePicker1.MaxDate = New Date(2010, 2, 7)
When my form loads, the value displayed is: 07 February 2010, as expected.
I then click the down arrow of the control, and the date changes to: 01 February 2010.
So are you saying that when you click the down arrow, the date stays as the 07 February 2010?
Thanks
Ross
Re: DateTimePicker Oddness
Quote:
Originally Posted by
dotnetster
Hiya,
Thanks for spending the time working on this.
What do you get when you just have the following:
Code:
DateTimePicker1.MinDate = New Date(2010, 2, 1)
DateTimePicker1.MaxDate = New Date(2010, 2, 7)
When my form loads, the value displayed is: 07 February 2010, as expected.
I then click the down arrow of the control, and the date changes to: 01 February 2010.
So are you saying that when you click the down arrow, the date stays as the 07 February 2010?
Thanks
Ross
Using the same code you are, when I click down arrow the date is still 07 and not 01 so I am not expereincing what you are with the calendar.
So in short no matter how I work the calendar I stay on 02/07/2010.
Re: DateTimePicker Oddness
Hi again,
I tried it again on another PC, my own one this time. I noticed that the version of the DateTimePicker looked different to the one on my PC. On my work PC, the control had a little calendar and an arrow down.
However, the DateTimePicker on my PC did not have a the little calendar pic. It looked more like a combox box.
So i'm just wondering are there different versions of the DateTimePicker?
Regards, and thanks
Ross
Re: DateTimePicker Oddness
Hi,
I found this article on the Connect site. It explains the problem that I am having, but unfortunately doesn't provide a solution.
Microsoft's official response, posted in August 2008 was:
"Unfortunately the issue that you have reported is caused by native Win32 DatePicker common control, a component external to WindowsForms and as such cannot be fixed by our team.
We have informed the responsible team about the issue, however they do not use this forum to track issues and hence we are closing it."
There was no fix, and the link to the workaround is dead. For more see:
http://connect.microsoft.com/VisualS...s-datetime-now
Regards,
Ross
Re: DateTimePicker Oddness
Re: DateTimePicker Oddness
Am hoping that the hotfix in: http://support.microsoft.com/kb/979535
will fix the bug...
Re: DateTimePicker Oddness
Update and possible solution. The problem appears to be specific to that wonderful OS that we all know and love. I refer of course to Vista. See this thread:
http://www.microsoft.com/communities...5-aa7d4966bc89
In particular, look at Zhi-xin Ye's response.