How Do I set the Value of a DateTimePicker Programmatically?

  • Thread starter Thread starter Manuel Canas
  • Start date Start date
M

Manuel Canas

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
 
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
 
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
 
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 said:
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?
 
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
 
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,

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
 
Back
Top