Results 1 to 12 of 12

Thread: [RESOLVED] [2005] Set DatePickerControl Value

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Resolved [RESOLVED] [2005] Set DatePickerControl Value

    I have a date stored in a variable (of type date). It has the month, day, and year. Is there one line of code that will put that date into a DateTimePicker control? I've tried .Value and a couple of others but I couldn't do it. Or do I have to set each part (month, day, year) individually?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: [2005] Set DatePickerControl Value

    I wouldn't have thought it, but trial and error suggests that .Text is the right property to set. Strange.

    Is there something else I should use instead?

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

    Re: [2005] Set DatePickerControl Value

    The Text property is type String. The Value property is type Date. If you have a variable of type Date then you can, and should, assign it directly to the Value property. There is no reason that that should not work. As you have chosen not to provide any details of what happened, which makes it all but impossible for us to diagnose the issue, that's about all I can say. If you "couldn't do it" then you must have got an error message. If we are not provided with that error message then how are we to help fix it?

    Furthermore, you should absolutely never be setting the Text property of a DateTimePicker and you should very rarely be getting it. Value is the main property of interest where the DateTimePicker control is concerned.
    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
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: [2005] Set DatePickerControl Value

    This first one works, the 2nd one does nothing (that I can see)...

    vb Code:
    1. dtpDateAssigned(index).Text = CStr(Assignment(index, c).DateAssigned)
    2.             dtpDateAssigned(index).Value = Assignment(index, c).DateAssigned

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

    Re: [2005] Set DatePickerControl Value

    So, is your question answered?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: [2005] Set DatePickerControl Value

    If I'm supposed to use the .Value property, then no, the question is not answered. I'm setting the DateTimePicker to a date but it's not responding in any visible way. When I use the .Text property, it changes as expected.

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

    Re: [2005] Set DatePickerControl Value

    Ok. What is the code that you currently have and is it generating an error?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: [2005] Set DatePickerControl Value

    I found the problem and fixed it.

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

    Re: [RESOLVED] [2005] Set DatePickerControl Value

    What was it (your solution may help someone else)?

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: [RESOLVED] [2005] Set DatePickerControl Value

    The code was called from a DataGridView CurrentCellChanged event. If the CurrentCell was in column(0) of the grid which was the name column, there was no date. The code was trying to put a nonexistent date into the DatePickerControl. Any of the other columns worked fine because they had dates.

    Also, after my initial post, I had changed when the code got fired and I did THAT wrong. So the code that set the DateTimePicker's date was never getting executed (after I edited the code). That made it look like nothing was happening.

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

    Re: [RESOLVED] [2005] Set DatePickerControl Value

    This is why you really need to give a complete explanation of what you're doing and exactly waht happens when you do it. Hurried, partial explanations don't give us a clear picture of the situation so diagnosing the issue is often difficult or impossible.
    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

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: [RESOLVED] [2005] Set DatePickerControl Value

    Sorry suh! I'll try to be mo bettah! I won't do dat no mo.

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