[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?
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?
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.
Re: [2005] Set DatePickerControl Value
This first one works, the 2nd one does nothing (that I can see)...
vb Code:
dtpDateAssigned(index).Text = CStr(Assignment(index, c).DateAssigned)
dtpDateAssigned(index).Value = Assignment(index, c).DateAssigned
Re: [2005] Set DatePickerControl Value
So, is your question answered?
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.
Re: [2005] Set DatePickerControl Value
Ok. What is the code that you currently have and is it generating an error?
Re: [2005] Set DatePickerControl Value
I found the problem and fixed it.
Re: [RESOLVED] [2005] Set DatePickerControl Value
What was it (your solution may help someone else)?
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.
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.
Re: [RESOLVED] [2005] Set DatePickerControl Value
Sorry suh! I'll try to be mo bettah! I won't do dat no mo.