Windows Develop Bookmark and Share   
 index > Windows Forms General > How to assign Empty Value to DateTimePicker?
 

How to assign Empty Value to DateTimePicker?

Hi, I would like to ask. The purpose of my application is to receive trouble/complain from customerson a software company.

It is a CUSTOMER SUPPORT SYSTEM.

So on the Support form, it consists of like this:

Support Officer Name: <textBox>

Support Time (Date & Time): <datePicker1> <timePicker1>

Customer Name : <textBox>

Contact Type : <comboBox>

Finish Time(Date & Time) : <datePicker2> <timePicker2>

[Ok] [Cancel]

"Support Officer Name:", "Support Time (Date & Time): ", "Customer Name :", "Contact Type :", "Finish Time(Date & Time) :" are labels.

Items on comboBox are: Fax, Mail and Telephone.

So how the customer contact the company is also documented.

"Ok"and "Cancel" are buttons.

Here is the case:

Today (2008/01/1712:10:05) there is a phone call from a customer whose having a problem with his application.

So the support officer open this Support form and start to add new entry.

IT IS POSSIBLE FOR THE SUPPORT OFFICER TO NOT FILL IN THE FINISH TIME because if the trouble does not finished today, it will continued tomorrow and so on. So there is no limit when the solution must be finished.

To complete that Finish Time, the support officer must be edit that data and fill the Finish Time.

How to do that(not fill the finish time)/manipulate the empty Finish Time by using datePicker and timePicker?

Thank you very much.

Christiawan  Thursday, January 17, 2008 3:31 AM

There's a nice sample of a nullable DateTimePicker at this link:

Yet Another Nullable DateTimePicker Control

Zhi-Xin Ye  Monday, January 21, 2008 7:35 AM

hi

you can check the datepirkcer text property for ex

1.

if(datetimepicker.text.trim().lenght !=0)

{

datetimetodayDate = datetimepicker.value

}

2. database datetime column must allow the nulls

smilesai  Thursday, January 17, 2008 7:34 AM

Ok for the data saving, I use String type but for temporary data variable, I use DateTime object, so if I use your code it would be like this:

if (dateTimePicker1->Text->Trim()->Lenght != 0)

{

DateTime ^dt = dateTimePicker1->Value;

MessageBox:Tongue Tiedhow(dt->ToString());

}

else MessageBox:Tongue Tiedhow("Not Ok.");

1. What still be a question is how to make the dateTimePicker value to null? The default when I ran my application is current time, like now in my computer is 17:22:44 so in the timePicker it is written 17:22:44 and when I click the button to process above code, it shows "Not Ok" which means that the dateTimePicker was not Null?

2. Are you sure that if I assign a null value to the DateTime object like I did above will not threw an exception when the project ran? I mean does the DateTime object support null value?

3. How to assign a null value to the dateTimePicker? Because I need it to handle this condition:

When user add data they are allowed not to fill the date because it can be edited later. If the date is empty, I give a "-" to the String variable because I use text file of CSV format to save all the data.

The problem is when user edit the data, how to display that empty data back on the dateTimePicker to show that it has not been completed yet?

How to solve this?

Thank you very much.

Christiawan  Thursday, January 17, 2008 8:26 AM
I had a similar problem that i solved by subclassing the DateTime picker. Instead of a NULL, I used the min time value. When ever the min time value was encountered, I formatted the output string as all spaces, effectively making the display time 'null'. The reason I used the minimum legal time was because a NULL threw exceptions at the most inopportune times

RickLH  Thursday, January 17, 2008 10:35 PM

Wow, that sounds great.. What is the time min value? 00:00:00? Can you please give me code sample ofyours which you have successfully developed?

Thankyou very much..

Christiawan  Thursday, January 17, 2008 11:48 PM

There's a nice sample of a nullable DateTimePicker at this link:

Yet Another Nullable DateTimePicker Control

Zhi-Xin Ye  Monday, January 21, 2008 7:35 AM

You can use google to search for other answers

Custom Search

More Threads

• Datetimepicker value comparing to string
• scrolling causes system to slow
• Scroll to control w/ Focus
• Question about RightToLeft Property
• Error While Sending Mail From ASP>NET
• Press Esc key to close a form containing many controls
• Drawing on pictureBox
• ListView control and Key Strokes
• Completely confused - .ico .bmp nightmares
• richtextbox scroll