Determine if a TextField has changed...?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to fire code when the user changes the value of a textbox. I only want it to fire when the user is finished eding the TextBox and leaves (not after each keystroke). I am using the Validating event (the Leave even seems similar), but this is called even when the user does not make a change. Is there a simple way to handle this other than manually setting boolean flags for each keystroke?

I also find that the Validating event is begin called even when I do a 'CancelUpdate' to undo the changes - I do not want this to happen. Again, is there a simple solution? Didn't older version of VB have an IsDirty function? Is there something similar

Thanks
Denise
 
Denise said:
I want to fire code when the user changes the value of a textbox. I
only want it to fire when the user is finished eding the TextBox and
leaves (not after each keystroke). I am using the Validating event
(the Leave even seems similar), but this is called even when the user
does not make a change. Is there a simple way to handle this other
than manually setting boolean flags for each keystroke?

I also find that the Validating event is begin called even when I do
a 'CancelUpdate' to undo the changes - I do not want this to happen.
Again, is there a simple solution? Didn't older version of VB have
an IsDirty function? Is there something similar?

Store the values you want to edit in a data layer (in variables, in an
object). If you leave a textbox, compare the value in the textbox to the
corresponding one in the data layer. You can validate it in the Validating
event, and, if ok, store the new value in the data layer.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Just save the value of the textbox and compare it in the validating event.


Dim lastSaved As String = ""
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating

If TextBox1.Text <> lastSaved Then

'--- Fire your event---
'---------------------

'-- Save to current text
lastSaved = TextBox1.Text
End If

End Sub
 
Hi Denise,

In addition to the others,

Store on the "Enter" event and check on the "Leave" event.

For this you can make in my opinion a generic routine by adding the handlers
for this in a loop to all your textboxes.

When that is a problem, message back, then I can see if I can make a sample
for you.

I hope this helps?

Cor
 
Back
Top