开发者

Detect text changed on textbox whilst ignoring databindings

开发者 https://www.devze.com 2023-02-14 09:32 出处:网络
I have some textboxes bound to a bindingsource and bindingnavigator. I want to detect when the values have changed and prompt the users to confrim if they want to update.

I have some textboxes bound to a bindingsource and bindingnavigator.

I want to detect when the values have changed and prompt the users to confrim if they want to update.

When the form is first initalised and when then binding navigator moves to the next record the text_changed event fires on textbox where I have a boolean to determine if things have changed.

Is there a way to set my boolean only when valid data changes have occured or a better way to detect if things ha开发者_如何学JAVAve changed


Typically the way to do this is to note when the backing property of the textbox has changed.

So instead of checking the UI event you would do something like

Public Class myClass
   private _myString As String = ""
   private _isDirty As Boolean
   Public Property MyString(ByVal _newString As String) As String
    Get
        Return _myStrig
    End Get
    Set
         If Not _newString.Equals(_myString) Then
              _myString = _newString
              _isDirty = true
         End If
    End Set
  End Property
  'You could also just put a property on IsDirty and check that
  Public Sub CanSave()
     Return _isDirty
  End Sub
End Class

Basically you verify that a value has actually changed before setting it, and then when you need to check if the Object isDirty you just check the _isDirty field.

You could also make use of INotifyPropertyChanged

0

精彩评论

暂无评论...
验证码 换一张
取 消