By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,569 Members | 1,630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,569 IT Pros & Developers. It's quick & easy.

How Do I set the Value of a DateTimePicker Programmatically?

P: n/a
Hi There,

I have this problem I'm trying to address but no luck so far, need your help
here.

How do I set the value of a DateTimePicker Programmatically?
When I do this: txtDate.Value = DateTimeNow the txtDate.Checked tells me
that is false. So nothing went in there. I know the datetimepicker has a
default value which is today's date and you can't do anything to get rid of
it, as far as I know.

Anybody that knows this out there, please help me out here.

Thanks very much.

Manuel



Nov 20 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
EdB
Try this

dtp1.SetDate(CDate("06/30/2004")) Example sets to June 30th, 2004

Ed

"Manuel Canas" wrote:
Hi There,

I have this problem I'm trying to address but no luck so far, need your help
here.

How do I set the value of a DateTimePicker Programmatically?
When I do this: txtDate.Value = DateTimeNow the txtDate.Checked tells me
that is false. So nothing went in there. I know the datetimepicker has a
default value which is today's date and you can't do anything to get rid of
it, as far as I know.

Anybody that knows this out there, please help me out here.

Thanks very much.

Manuel



Nov 20 '05 #2

P: n/a
Thanks Ed,

The SetDate is not part of the System.Windows.Form.DateTimePicker.

"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:3cDPc.18058$yT2.228@clgrps13...
Hi There,

I have this problem I'm trying to address but no luck so far, need your help here.

How do I set the value of a DateTimePicker Programmatically?
When I do this: txtDate.Value = DateTimeNow the txtDate.Checked tells me
that is false. So nothing went in there. I know the datetimepicker has a
default value which is today's date and you can't do anything to get rid of it, as far as I know.

Anybody that knows this out there, please help me out here.

Thanks very much.

Manuel


Nov 20 '05 #3

P: n/a
Manuel,

This works fine for me

DateTimePicker1.Value = Now
and this as well
Me.DateTimePicker1.Value = New Date(2004, 8, 3)

I hope this helps?
Cor
Nov 20 '05 #4

P: n/a
Thanks guy for your replies.
but unfortunatelly, none of it works.
Cor, I already tried the ones that you said, but it's not going anywhere.
when I call the update, it tells that the datetimepicker it's null!!
I'm ready to give up on this one.

Manuel
"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:3cDPc.18058$yT2.228@clgrps13...
Hi There,

I have this problem I'm trying to address but no luck so far, need your help here.

How do I set the value of a DateTimePicker Programmatically?
When I do this: txtDate.Value = DateTimeNow the txtDate.Checked tells me
that is false. So nothing went in there. I know the datetimepicker has a
default value which is today's date and you can't do anything to get rid of it, as far as I know.

Anybody that knows this out there, please help me out here.

Thanks very much.

Manuel


Nov 20 '05 #5

P: n/a
EdB
Sorry about that Manuel, the SetDate is for the MonthCalendar control.

But if I do this with a DateTimePicker:

DateTimePicker1.Value = CDate("06/30/2004")

Then do this:

MsgBox(DateTimePicker1.Value)

I get 6/30/2004

Hope that helps.

"Manuel Canas" wrote:
Thanks Ed,

The SetDate is not part of the System.Windows.Form.DateTimePicker.

"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:3cDPc.18058$yT2.228@clgrps13...
Hi There,

I have this problem I'm trying to address but no luck so far, need your

help
here.

How do I set the value of a DateTimePicker Programmatically?
When I do this: txtDate.Value = DateTimeNow the txtDate.Checked tells me
that is false. So nothing went in there. I know the datetimepicker has a
default value which is today's date and you can't do anything to get rid

of
it, as far as I know.

Anybody that knows this out there, please help me out here.

Thanks very much.

Manuel



Nov 20 '05 #6

P: n/a
Manuel,

Did you bind the DateTimePicker maybe?

Cor
Thanks guy for your replies.
but unfortunatelly, none of it works.
Cor, I already tried the ones that you said, but it's not going anywhere.
when I call the update, it tells that the datetimepicker it's null!!
I'm ready to give up on this one.

Nov 20 '05 #7

P: n/a
* "Manuel Canas" <mc*****@hotmail.com> scripsit:
but unfortunatelly, none of it works.
Cor, I already tried the ones that you said, but it's not going anywhere.
when I call the update, it tells that the datetimepicker it's null!!


Can you post some code?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #8

P: n/a
DayTimePicker is bound to a field in the database.
"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:3cDPc.18058$yT2.228@clgrps13...
Hi There,

I have this problem I'm trying to address but no luck so far, need your help here.

How do I set the value of a DateTimePicker Programmatically?
When I do this: txtDate.Value = DateTimeNow the txtDate.Checked tells me
that is false. So nothing went in there. I know the datetimepicker has a
default value which is today's date and you can't do anything to get rid of it, as far as I know.

Anybody that knows this out there, please help me out here.

Thanks very much.

Manuel


Nov 20 '05 #9

P: n/a
Hi Manual,

Than you do not have to change the datatimepicker directly however the field
in the database where you have bounded it to.

Cor
Nov 20 '05 #10

P: n/a
Hey Cor,

But I have to set the value of the DateTimePicker when the user adds a new
record, otherwise, the user will HAVE TO click on the control and choose
today's Date.

The Sample that Ed gave me works fine: DateTimePicker1.Value =
CDate("06/08/2004") it goes in with no problem, but when I want to set
today's date in there, it craps out.
Let's say: DateTimePicker1.Value = CDate(Now) Not Good.
DateTimePicker1.Value = CDate(DateTime.Now) Not Good.

What can I do now?????
"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:3cDPc.18058$yT2.228@clgrps13...
Hi There,

I have this problem I'm trying to address but no luck so far, need your help here.

How do I set the value of a DateTimePicker Programmatically?
When I do this: txtDate.Value = DateTimeNow the txtDate.Checked tells me
that is false. So nothing went in there. I know the datetimepicker has a
default value which is today's date and you can't do anything to get rid of it, as far as I know.

Anybody that knows this out there, please help me out here.

Thanks very much.

Manuel


Nov 20 '05 #11

P: n/a
Manuel,

This works for me.

Private Sub Form1_Load(ByVal sender As Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable("dt")
dt.Columns.Add("tijd", GetType(System.DateTime))
Dim dv As New DataView(dt)
dv.AddNew()
dv(0)(0) = Now.AddDays(1)
Me.DateTimePicker1.DataBindings.Add("Value", dv, "tijd")
End Sub

I hope as well for you?

Cor

Nov 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.