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!

date time picker checked property

Status
Not open for further replies.

cluelessAnyAdvise

Programmer
Jun 24, 2005
17
US
Hi

Is there any way to control the behavior of the check box on the datetime picker control that is bound to dataset.

I have a dateTimePicker control on a Windows Form (VB.NET),
which is bound to a dataset (database column of date type).

Following properties are set -
editfldName.Checked = False
editfldName.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.dsName, "tblName.fldName"))
editfldName.ShowCheckBox = True

As I understand it is not possible to set a DateTimePicker to null value (if the DB column has null). So there is no way to clear out the datetime picker's text itself. Currently it shows the default date (Date.Now) when dataset column has no date in it. The check box next to it is always checked once the data is loaded on the form.
So there is no visual indication for the users to determine if the value shown is from dataset or default.
So I'd like to show -

checkbox as checked if the value in <editfldName> is the one from dataset column.
checkbox as NOT checked when the value is default value of datetimepicker (ie. Date.Now)

Any suggestions? Please help.


Thanks

 
I've never tried this with the DateTimePicker, but it might be possible to create your own control, inheriting from it and adding the functionality that you require.

Hope this helps.
 
Thanks for the quick response.
Your suggestion makes perfect sense. However I still am not sure which event i need to handle and which property i should check to determine when to uncheck the checkbox. I tried various events like BindingContextChanged, Validated, valuechanged to name few. None of them serve the purpose.

Below is the what i came up with -

Public Class datetmpicker
Inherits System.Windows.Forms.DateTimePicker
Public Sub New()
Checked = False
Enabled = False
Format = System.Windows.Forms.DateTimePickerFormat.Short
ShowCheckBox = True
Size = New System.Drawing.Size(120, 22)
End Sub

Private Sub myBindingContextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.BindingContextChanged
If Value = CDate(Text) Then
Checked = False
End If
End Sub

End Class

First of all obviously this will not work as BindingContextChanged event is not raised everytime data bound to the instance changes. Can you guide me which event i should handle here ?
I am also not sure if the text would have null value when the data column has null in it. I know the value will be default system date but i am not sure what the text would have when data column has null in it.

Any idea / suggestions ?


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top