|
-
Feb 11th, 2010, 06:15 AM
#1
Thread Starter
New Member
DateTimePicker Oddness
Hi all,
I'm having a bit of bother with the DateTimePicker control in .NET 3.5. I created a very simple form. It consists of just one DateTimePicker control called "DateTimePicker1". In the Load event of the form, I placed the following code:
DateTimePicker1.MinDate = "01/02/2010"
DateTimePicker1.MaxDate = "07/02/2010"
There is no other code. Again, this example is for illustrative purposes only. The current date is today, i.e., 11 February 2010
Ok.
When I fire up the application, the date displayed in the control is "07 February 2010". All fine.
However, when I click the little calendar/down arrow on the control to pick a date, the date changes to "01 February 2010". I don't want this to happen.
If I then select a date from control, say: 03 February 2010. The date stays there. If I click the calendar/down arrow on the control again to select another date, the date displayed in the control changes back to "01 February 2010".
It seems that this behaviour happens when the current date, in this case: 11 February 2010, is greater than the MaxDate assigned to the control. Is there any way around this? I don't want the date to change when I click the down arrow on the control.
Thanks in advance,
Ross
-
Feb 11th, 2010, 07:47 AM
#2
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?
-
Feb 11th, 2010, 08:01 AM
#3
Thread Starter
New Member
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
-
Feb 11th, 2010, 08:11 AM
#4
Thread Starter
New Member
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
-
Feb 11th, 2010, 09:34 AM
#5
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)
-
Feb 11th, 2010, 11:05 AM
#6
Thread Starter
New Member
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
-
Feb 11th, 2010, 11:32 AM
#7
Re: DateTimePicker Oddness
 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?
-
Feb 11th, 2010, 11:50 AM
#8
Thread Starter
New Member
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
-
Feb 11th, 2010, 12:00 PM
#9
Re: DateTimePicker Oddness
 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.
-
Feb 11th, 2010, 12:28 PM
#10
Thread Starter
New Member
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
-
Feb 11th, 2010, 01:25 PM
#11
Re: DateTimePicker Oddness
 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.
-
Feb 11th, 2010, 04:33 PM
#12
Thread Starter
New Member
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
-
Feb 21st, 2010, 07:37 PM
#13
Thread Starter
New Member
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
-
Feb 21st, 2010, 07:45 PM
#14
Thread Starter
New Member
Re: DateTimePicker Oddness
-
Feb 21st, 2010, 08:13 PM
#15
Thread Starter
New Member
Re: DateTimePicker Oddness
Am hoping that the hotfix in: http://support.microsoft.com/kb/979535
will fix the bug...
-
Feb 22nd, 2010, 08:05 AM
#16
Thread Starter
New Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|