Results 1 to 11 of 11

Thread: Customize DateTimePicker

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    14

    Customize DateTimePicker

    Hi,

    I'm trying to customize a DateTimePicker to "dd-MM-yyyy" and not "dd/MM/yyyy", wich is the actual format. I used the following code, that didn't work:
    Code:
    DateTimePicker1.Format = DateTimePickerFormat.Custom
            DateTimePicker1.CustomFormat = "dd-MM-yyyy "
    Does anyone knows how can i overcome this problem?
    Thanks

  2. #2
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    UK
    Posts
    285

    Re: Customize DateTimePicker

    1. Set the DateTimePicker's Format property to DateTimePickerFormat.Custom.
    2. Set the DateTimePicker's CustomFormat to the string above.

    (you can do step 1 in the designer)

    WHY THE HELL DON'T I READ THE QUESTION BEFORE I POST???!!!!

    The answer to your question is that the string format is incorrect. You must use uppercase `M`s: "dd-MM-yy"

    OKAY! THIS IS GETTING SILLY...
    I DON'T KNOW WHY YOUR EFFTING CODE WON'T WORK, AND I'M NOT SURE I EFFTING CARE ! (I'm off to get my head/eyesight examined!!!)
    Last edited by bigMeUp; Jan 11th, 2008 at 07:40 AM.

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Customize DateTimePicker

    Quote Originally Posted by bigMeUp
    1. Set the DateTimePicker's Format property to DateTimePickerFormat.Custom.
    2. Set the DateTimePicker's CustomFormat to the string above.

    (you can do step 1 in the designer)
    1. He did "DateTimePicker1.Format = DateTimePickerFormat.Custom" from his original post
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    UK
    Posts
    285

    Re: Customize DateTimePicker

    dbasnett: Allow me, kind sir, to refer you to my edits!

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Customize DateTimePicker

    I do that also, matter of fact I missed that they had set format to custom the first time I read it, but caught myself before I posted. My excuse is that I am not as young as I used to be. Your edits made me

    I copied / pasted the code from the original post and it worked. So "Does anyone knows how can i overcome this problem?" is no, I think, because we don't knows what the problem is.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Customize DateTimePicker

    I tried this today
    Code:
            DateTimePicker1.Format = DateTimePickerFormat.Custom
            DateTimePicker1.CustomFormat = "dd-MM-yy "
    and it displayed 11-01-08

    and then this

    Code:
            DateTimePicker1.Format = DateTimePickerFormat.Custom
            DateTimePicker1.CustomFormat = "dd-MMM-yy "
    and it displayed 11-Jan-08

    BTW - I tried 2 digit and 4 digit years and the results were as expected.
    Last edited by dbasnett; Jan 11th, 2008 at 07:38 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    14

    Re: Customize DateTimePicker

    Thank you all!

    So, the conclusion is that you don't know why is this hapening, because the code is correct, wright?

    So,...i don't know how to overcome this....

    Thanks both

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Customize DateTimePicker

    Quote Originally Posted by mqdias
    Thank you all!

    So, the conclusion is that you don't know why is this hapening, because the code is correct, wright?

    So,...i don't know how to overcome this....

    Thanks both
    WE don't know what IS happening.

    It is hard to diagnose "I used the following code, that didn't work" and "Does anyone knows how can i overcome this problem?"
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Customize DateTimePicker

    Try
    vb.net Code:
    1. Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
    2.         MessageBox.Show(DateTimePicker1.Value.ToString("dd-MM-yyyy"))
    3.     End Sub

  10. #10
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Customize DateTimePicker

    When you say "it didn't work", what exactly does it do and what is the expected result?

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Customize DateTimePicker

    This is actually resolved. He also posted the same question on another JM Forum.

    He had code that interacted with an application called AutoDesk, and that was causing problems with his VB code. He moved his VB code above the code that interacts with this application, and everything worked for him.

    @mgdias: you could help us out by pulling down the Thread Tools menu and clicking the Mark Thread Resolved menu item. That will let everyone know that you have your answer.

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