Does anyone have a clue where the problem is. I have a data entry form with databound textboxes. When I'm in a textbox that contains a datetime value and I press Del key, and then leave this box, the date value just reapears. So there is no way to clear once entered date. On other boxes that contain just text this doesn't happen. I'm using this code to format the date so the user just enters for instance 040804 for 04.08.2004 , but even without this code the value stays in no matter how I clear it. It also doesn't format as a ShortDate string despite:
udt = Date.Parse(udt).ToShortDateString
Can anyone help me.
Private Sub editdatum_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles editdatumu.Leave, editdatumr.Leave, editdatump.Leave
Dim udt As String
udt = CType(sender, TextBox).Text
If udt > "" Then
Try
If udt.IndexOf(".") = -1 Or udt.IndexOf(",") = -1 Then
udt = udt.Insert(2, ".")
udt = udt.Insert(5, ".")
End If
udt = Date.Parse(udt).ToShortDateString
CType(sender, TextBox).Text = udt
CType(sender, TextBox).BackColor = Color.White
Catch ex As System.Exception
Dim potvrda As MsgBoxResult
potvrda = System.Windows.Forms.MessageBox.Show("Neispravan datum!" & Chr(13) & ex.Message, "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
If potvrda = MsgBoxResult.OK Then
CType(sender, TextBox).BackColor = Color.Yellow
CType(sender, TextBox).Focus()
CType(sender, TextBox).SelectAll()
Else
CType(sender, TextBox).BackColor = Color.White
End If
End Try
Else
CType(sender, TextBox).BackColor = Color.White
End If
End Sub