Results 1 to 16 of 16

Thread: DateTimePicker Oddness

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    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

  5. #5
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    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)

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    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

  7. #7
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: DateTimePicker Oddness

    Quote Originally Posted by dotnetster View Post
    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?

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    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

  9. #9
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: DateTimePicker Oddness

    Quote Originally Posted by dotnetster View Post
    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.

  10. #10

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    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

  11. #11
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: DateTimePicker Oddness

    Quote Originally Posted by dotnetster View Post
    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.

  12. #12

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    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

  13. #13

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    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

  14. #14

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    Re: DateTimePicker Oddness


  15. #15

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    Re: DateTimePicker Oddness

    Am hoping that the hotfix in: http://support.microsoft.com/kb/979535
    will fix the bug...

  16. #16

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    11

    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
  •  



Click Here to Expand Forum to Full Width