469,299 Members | 2,065 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

The code to change dateTimePicker control not working.

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;
}
Dec 29 '05 #1
5 5274
dtpLastOdoDate.Update(); // ??

"Alpha" wrote:
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;
}

Dec 30 '05 #2
Thanks John. I added the code you suggested
dtpLastOdoDate.Update();
but it still not working.

"John" wrote:
dtpLastOdoDate.Update(); // ??

"Alpha" wrote:
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;
}

Dec 30 '05 #3
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.

Dec 30 '05 #4
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.

"chandra" wrote:
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.

Dec 30 '05 #5
On Thu, 29 Dec 2005 12:37:02 -0800, "Alpha"
<Al***@discussions.microsoft.com> wrote:
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.
Dec 31 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Richard | last post: by
4 posts views Thread by Jacek Jurkowski | last post: by
3 posts views Thread by Darin | last post: by
8 posts views Thread by gumi | last post: by
7 posts views Thread by Clamara | last post: by
3 posts views Thread by Charlie | last post: by
4 posts views Thread by jehugaleahsa | last post: by
2 posts views Thread by Todd Carnes | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.