Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTimePicker displays today's date instead of displaying its actual Value

We have a couple of DateTimePickers on a custom UserControl, on a Form. They are visible, but not enabled (for display purposes only). When the UserControl is loading, the DateTimePickers are assigned values from a DataRow that came from a DataSet which stores a single record returned from a SQL Server stored procedure.

There is an inconsistent behavior in which the users sometimes see today's date instead of the date that was assigned to the DateTimePicker. It doesn't seem to matter whether I assign the date I want to the .Value property or the .Text property:

txtstart.Value = (DateTime) dr["Group_Start_Date"];
txtend.Text = dr["Term_Date"].ToString();

I expect that of the two statements above, the one using the Value property is more appropriate. But, in both cases, today's date is displayed to the user regardless of the values that were in the database. In the case of txtstart.Value, Visual Studio shows me that the value was assigned as expected. So why isn't it displaying that date to the user instead of today's date?

like image 414
Matt Avatar asked Oct 23 '09 18:10

Matt


People also ask

How do you only show time in date picker?

In the Data type Format dialog box, do one of the following: To format the control to show the date only, select the display style that you want in the Display the date like this list. To format the control to show the time only, select the display style that you want in the Display the time like this list.

How do you set a date picker?

If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C. Under Insert controls, click Date Picker. In the Date Picker Binding dialog box, select the field in which you want to store the date picker data, and then click OK.


2 Answers

I found the answer. You MUST set the checkbox value to checked to indicate a non-null value.

this.dateSold.Checked = true; // set to true or false, as desired this.dateSold.ShowCheckBox = false;

like image 95
taylorg Avatar answered Oct 11 '22 15:10

taylorg


I was having trouble with this too and found that you indeed need to set the .Checked value to True.

I set the Checked property in the properties window and it still didn't work so I just set it in code before assigning the value and that fixed the problem.

like image 44
Tom Slayton Avatar answered Oct 11 '22 17:10

Tom Slayton