Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to dispaly blank on date control 1

Status
Not open for further replies.

HRHK

Programmer
Jun 5, 2005
83
US
Initially before the user populates the date on date picker control, I would like to display blank on the date control.
Is there a easy way to do this? Thanks.
 
No, not really. If you need to prepopulate it with a value, either use today's date, or a value that makes sense for the application.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
I hit this problem recently and opted to build a user control to combine a datepicker with a checkbox.

Checked: user control value property is set to datepicker value
Unchecked: the datepicker is disabled and the user control's value property is set to NULL.

Works fine for me and makes things a little clearer for users - I think.

Hope this is useful - just picking my way through last months threads.
 
Hi techsmith

Could you please explain your workaround a little bit in detail. I am a newbie. I am experiencing the same problem...had posted similar questions few days back.
From your comments what i understand is -
in your control you used combination of two controls datetime picker and checkbox and then controled the check uncheck property based on value of datetime control.

The problem i am experiencing is whenever i bind the control to its value property, i get exception error for casting DBnull (in case date is null) to value property of the control (derived from datetimepicker). This is because datetime picker does not support DBnull. If i bind the control to its text property it does not throw such exception.
I wonder how did you bind your control to value property?
I am also not sure -
- how to determine if the value that datetime picker is displaying is default or the one from datacolumn.
- when should the checked / unchecked of checkbox take place.
On my form I have a datagrid + a panel displaying details of the grid row. The form has basic add / modify / delete / view with search functionality.

Any help in this matter is highly appriciated.
I have wasted a lot of time on this one...
Please help.

 
To make a blank show for the date in a DateTimePicker control:

DateTimePicker1.Format = DateTimePickerFormat.Custom
DateTimePicker1.CustomFormat = Chr(32)



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Sorry that wont work as I am already using the custom format property to display date and time in certain format.
Plus when you set the property that way you never get to see the actual date (even when date is selected from calendar).
any other ideas ?
 
Try this:

Private Sub DateTimePicker1_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles DateTimePicker1.CloseUp

If sender.CustomFormat = Chr(32) Then
sender.CustomFormat = <your custom format>
End If

sender.Text = sender.Value

End Sub

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
yes that did work Thanks for your help.
By clearing up the date field it is clear to the user that he / she has not selected the date yet.
However I think use of check box (to indicate if the date visible on the control is default or data driven) will be better alternative. This is because -

There are couple of issues in simply blanking out the date.

- In add / modify mode when the date is blank, the user cannot adjust the date directly by editing it, he has to use calendar to do so. If we were to not to blank out the default date (and simply uncheck the box) the date or time can be adjusted in editbox itself.
- In display mode we still need a logic to figure out how to blank the field if dataset has dbnull.
- the check box still remains checked (even when the date itself is blanked out, even when i have the checked = false) This is because the check box property of datetimepicker is dependent on value and there will always be a value - if not from dataset then default.

However this is definitely one step forward. I would like to get some suggestions on how the check box itself can be manipulated.
 
You may be beyond looking at different options at this point, but did you consider changing the font color when a date is selected to highlight the change?

Dale
 
Yes sure i can use fonts or colors to differentiate the user input (in add/modify) or dataset value (in display mode) v/s default value. With Jebenson's guidance, I got the blanking out of field to work under all scenarios. But these are all workarounds.
Use of checkbox to indicate, the value is user accepted value and not a default, makes more sense (talking to end users that is what they would like to see as well...).
I am really puzzled as why datetimepicker class does not provide this functionality when they already have a checkbox as part of the control.
From various posts on the same subject, it looks like many programmers have stumbled upon this in the past as well.

Techsmith had mentioned in his reply that he got the checkbox to work. So I was wondering how. Or if anyone else has got that to work it will be really helpful to share that.

The main cause of this is the fact that value property does not allow DBNull otherwise there would not be any problem in working of checkbox. The checkbox looks at value property to determine whether it should be checked or not...

Thank you all for taking interest in this post as this post is repeated by various users at various times. I hope we find some solution to this problem.





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top