About textbox Validating, Validated & TextChanged

  • Thread starter Thread starter Steven Spits
  • Start date Start date
S

Steven Spits

Hi,

I have a textbox that should be numeric, so I've written some code in the
Validating event. When the text was changed (and if it's valid!), I need to
compute some other values. I've done this in the Validated event.

However, when the users tabs over that field, the Validating & Validated
event is triggered even if nothing changed.

I've solved this by setting textbox.Tag to false in the Enter event. In the
TextChanged event the tag is set to true and in the Validated event I only
run the code if the tag is true.

Isn't there a better way? Some .IsDirty property?

Steven

- - -
 
Hi Steven,

I think your approach is quite fine. There is no out-of-the-box approach to
check whether a textbox is "dirty". However, with your approach, the user
might have edited the value and then reverted it back, but you mark the text
box as dirty upon the first change. Might be better to remember the original
value on Enter and then compare it with the current one upon Validating.
 
Back
Top