A TextBox Control has a simple DataBinding. When the TextBox Validating Event detects an error, sets e.Cancel=True and exits, the DataSource is incorrectly updated with the invalid data.Demo program...1) creates a simple Bind between a TextBox and a test object.2) defines a Validating event on the TextBox3) Validating event detects the blank field and sets e.Cancel=true.Sample Code:Public Class Form1 Private _anObject As New aClass Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load TextBox1.DataBindings.Add(New Binding("Text", _anObject, "myProperty")) End Sub Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating Debug.Print("Validating: ctrl:'{0}' obj:'{1}", TextBox1.Text, _anObject.myProperty) If TextBox1.Text = "" Then Debug.Print("Set Cancel=true; should not update bound object") e.Cancel = True End If End SubEnd ClassPublic Class aClass Private _myProperty As String = "aaaa" Public Property myProperty() As String Get Return _myProperty End Get Set(ByVal value As String) Debug.Print("Updating: _myProperty:'{0}' value:'{1}'", _myProperty, value) _myProperty = value End Set End PropertyEnd Class
Version
Please wait...