Results 1 to 13 of 13

Thread: datetimepicker giving problem

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    965

    datetimepicker giving problem

    hi, i have three portions of my question?
    1) does datetimepicker picks up the current date of system automatically or not?

    2) if it picks up so it does not show the current date to me on my form? why is it so?

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: datetimepicker giving problem

    Nope, it won't pick it up by default.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

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

    Re: datetimepicker giving problem

    When a DateTimePicker is created, it's Value is set to the current date and time. If you don't set the Value property explicitly, either in the designer or in code, then that's what it will display. I don;t understand your second question.
    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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    965

    Re: datetimepicker giving problem

    Quote Originally Posted by jmcilhinney View Post
    When a DateTimePicker is created, it's Value is set to the current date and time. If you don't set the Value property explicitly, either in the designer or in code, then that's what it will display. I don;t understand your second question.
    HI Jmcilhinney, its right that it picks up the default date and time, but when i change its value property so it shows the same. but the thing i want is that, I want that when my form is displayed so it always show the current date of the system? suppose after three months i execute my project so it does show me that date which will be after three month? how do i do this?

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

    Re: datetimepicker giving problem

    I'm afraid that I'm still not clear what you want. If you have a form with a DateTimePicker on it, when you display that form, it will show the current date and/or time in the control unless you set it to something else. If you want something else then set it to something else; if you don't then don't. Are you actually asking how to save the date/time between sessions?
    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

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    965

    Re: datetimepicker giving problem

    Quote Originally Posted by jmcilhinney View Post
    I'm afraid that I'm still not clear what you want. If you have a form with a DateTimePicker on it, when you display that form, it will show the current date and/or time in the control unless you set it to something else. If you want something else then set it to something else; if you don't then don't. Are you actually asking how to save the date/time between sessions?
    yes whe i want that when i display that form, it shows the current date in the control unless you set it to something else. but it does not happen here. when i select one date in value property so it always show the same in control.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: datetimepicker giving problem

    *sigh* right... because you selected a date in the value property of the control... remove the date from the value property, let it reset itself and run the app again, this time DON'T select a date during design time.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    965

    Re: datetimepicker giving problem

    hi techgnome, how it can be possible to keep the value property empty. this is not possible. when you leave the value property empty so it gives error that this is not valid value

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

    Re: datetimepicker giving problem

    I'm still not 100% sure what you're asking for but let me describe the way the DateTimePicker works and see if that provides the information you need.

    The DateTimePicker is basically an interface to display a DateTime value and allow the user to change it. The most significant property is Value, which is type DateTime. It contains the value that is displayed to the user and, if the user enters a new value, the Value property is updated.

    Because DateTime is a value type, the Value property must always have a value, i.e. it can never be "null" or Nothing. As with all value type fields and properties, if you assign Nothing to the DateTimePicker.Value property, it will use the default value for the type, which is 12:00 AM on 1/1/0001.

    When a DateTimePicker object is created, the Value property is set to the current date and time by default. When you add a control to your form in the designer, it will display the current date and time at that moment. The Value will stay at that date and time until it has reason to refresh, e.g. you close the form and then re-open it. When you run the application, the DateTimePicker control gets created when the form is created. As such, the control will display the current date and time at that moment.

    If you want the control to display a specific date and time then you must set the Value property to that value, either in the designer or in code. If you don't want it to display a specific date and time then don't set the Value property.

    Now, as I said, the Value property must always have a value. As such, the control will always display a date and/or time. If you don't want a value displayed in the control then you can do it, but it's a bit fiddly. You need to set the ShowCheckBox property to True so that the control displays a check box. You can then use the state of that box, which corresponds to the Checked property, to determine whether the control represents a DateTime value or not. If Checked is False then you can set the Format property to Custom and the CustomFormat property to a string containing a single space character. The Value property will still contain a DateTime value but it won't be displayed to the user. You can then get a nullable DateTime value from the control like so:
    vb.net Code:
    1. Dim actualValue As Nullable(Of DateTime)
    2.  
    3. If myDateTimePicker.Checked Then
    4.     actualValue = myDateTimePicker.Value
    5. Else
    6.     actualValue = Nothing
    7. End If
    That's basically all you need to know about the DateTimePicker. If that doesn't answer your question then you're going to have to state more clearly what your question is. I assume that English is not your first language but you need to be clear. If you have to write a long post to do so then write a long post. Don't try to save yourself keystrokes at the expense of clarity. Providing too much information is better than providing too little.
    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

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    965

    Re: datetimepicker giving problem

    Quote Originally Posted by jmcilhinney View Post
    I'm still not 100% sure what you're asking for but let me describe the way the DateTimePicker works and see if that provides the information you need.

    The DateTimePicker is basically an interface to display a DateTime value and allow the user to change it. The most significant property is Value, which is type DateTime. It contains the value that is displayed to the user and, if the user enters a new value, the Value property is updated.
    hi jim, in bold text you said that changing will automatically update that new value into datetimepicker right? my qeustion is here that when it is updated so wil it display the same value until the new value is given?

  11. #11
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: datetimepicker giving problem

    Quote Originally Posted by Abid Durrani View Post
    hi jim, in bold text you said that changing will automatically update that new value into datetimepicker right? my qeustion is here that when it is updated so wil it display the same value until the new value is given?
    It doesn't store the user's selection until you explicitly write the code to save it and restore it on the next loading.

    So, if you want to keep the date value of the previous user remain unchanged, then you have to save that value to somewhere (say MySettings) and then next time, another user opens this form, you should have the code to load the previously saved value and display it in the DateTimePicker.


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    965

    Re: datetimepicker giving problem

    Quote Originally Posted by akhileshbc View Post
    It doesn't store the user's selection until you explicitly write the code to save it and restore it on the next loading.

    So, if you want to keep the date value of the previous user remain unchanged, then you have to save that value to somewhere (say MySettings) and then next time, another user opens this form, you should have the code to load the previously saved value and display it in the DateTimePicker.

    hi i want that whenever i open my form on which i have datetimepicker control, so it show me the current date.

  13. #13
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: datetimepicker giving problem

    Quote Originally Posted by Abid Durrani View Post
    hi i want that whenever i open my form on which i have datetimepicker control, so it show me the current date.
    You mean this ?

    vb.net Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         DateTimePicker1.Value = DateAndTime.Today
    3.     End Sub

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

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