Binding the date field to textbox

  • Thread starter Thread starter Taras
  • Start date Start date
T

Taras

Hi,

I have the problem with binding the textbox with date field in the table of
the dataset.

The problem is that if the entered text in the textbox isn't of the correct
type (for example "dfhd" instead of "12.6.2003"), the text gets
automatically overwritten by the old value. That way the user has to type
everything all over again instead of just correcting the entered value.

Is there a way to prevent old value to overwrite the entered text?

I used the following code to bind the textbox to a dataview...

Dim objBinding As New Binding("Text", ds.NETBill.DefaultView, "Date")

AddHandler objBinding.Format, AddressOf FormatDate

txtDatum.DataBindings.Add(objBinding)



....and following code to validate entered text...

Private Sub txtDatum_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtDatum.Validating

If Not ControlValue.CheckValue (txtDate, ControlValue.ETip.tDate,
ds.NETRacun.DefaultView(0)) Then

e.Cancel = True

End If

End Sub



Regards,

Taras
 
I'm not positive, but I think that's the default behavior by design. Two
things come to mind, but perhaps there's a more elegant answer.
1) You could check key_down and make sure that the user only enters number
or the character tokesn of your choosing much like a numeric text box. It
doesn't take much to check for the position either, so you can be sure you
get a real date.
2) You could use a DateTimePicker control instead (however for null dates,
it defaults to the current date's date which isn't always cool).

There's probably something more elegant, but this may be some help.

Bill
 
Back
Top