Trigger event when changing value of a textbox C#

Asked

Viewed 1,778 times

1

Guys, I’m starting in c# and I’m having a problem. I’m working with Windows form. I’m using the Textchange event in a textbox, and with each key pressed in the field it triggers the event. I need the event to be triggered only when the field value is fully "typed" and shift focus (Avascript onchange event type).

Any idea?

2 answers

1


Use the event Leave of TextBox.

Ex.:

public void textbox1_Leave(object sender, EventArgs e)
{
    //Fazer alguma coisa
}
  • It is the same case that I commented in the answer below.

  • Probably there is no event you are looking for...

  • You can check if the field has been modified, there is some property?

  • I think there is. Just a minute @Marcosvinicius

  • @Marcosvinicius uses a textchange flag to change it to true, indicating that the control has been changed. in the Leave event check if the flag is true ai executes its logic and passes the flag to false.

  • That’s an idea. Thank you!

  • One remark, I have my fields all in a bindingSource. Maybe by it I get something.

Show 2 more comments

0

The Onchange js event in c# is the "Validating" property, it’s the same thing, instead of Textchange, use Validating.

  • With Validating if you do not change the value of the field and change focus it runs. That is to say if I have a phomulário and user go pressing the entrer key (change focus) will trigger event of all fields. I don’t think it’s ideal.

  • There you will need to put a validation to more friendly, the language will never know when the user actually typed.

  • Okay, I’ll do one more search and I’ll be back for a callback.

  • I decided to use the Leave event in some cases and the textChange in others. vlw by the tips! @jbueno

Browser other questions tagged

You are not signed in. Login or sign up in order to post.