The code to change dateTimePicker control not working.

G

Guest

I have a DateTimePicker control that originally displays "1/1/1900" on
screen. I want to change it to current date when a user clicks on it. I use
the follow code but nothing is happening. Can someone tell me what I'm doing
wrong?
Thanks, Alpha

private void dtpLastOdoDate_Click(object sender, System.EventArgs e)
{
dtpLastOdoDate.Value = DateTime.Today.Date;
}
 
G

Guest

Thanks John. I added the code you suggested
dtpLastOdoDate.Update();
but it still not working.
 
C

chandra

i doubt we have a click event for the datetimepicker control.

instead to achieve ur thing. write the code in Enter event handler of
the datetimepicker control.
 
G

Guest

There is a Click event but it does nothing with the code I put in there. The
Enter event is working out just great. Thank you Chandra.
 
M

mablejune

I have a DateTimePicker control that originally displays "1/1/1900" on
screen. I want to change it to current date when a user clicks on it. I use
the follow code but nothing is happening. Can someone tell me what I'm doing
wrong?
Thanks, Alpha

private void dtpLastOdoDate_Click(object sender, System.EventArgs e)
{
dtpLastOdoDate.Value = DateTime.Today.Date;
}

The DateTimeOicker display defaults to the current date and time. You
must be setting the vale of it to null or something in your code.

Why must the user click the control to get it to display the current
date? Why not just let it display the default. If you don't want the
time, just set the Format property to Short.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top