views:

48

answers:

2

using winforms, c#, vs 2008

So i have textbox1, textbox2 and textbox3 on a winforms.

Textbox3.text = textbox1.text + textbox2.text.

I need textbox3 to be updated whenever the contents of textbox1 and textbox2 have been changed either manually or programmatic.

The problem is if i use textbox textchanged event it keeps firing as one types in the textbox. I need a way to call my method to fill textbox3 after either tb1 or tb2 have been FINISHED changing programmaticly or via key entry, and not fire everytime a letter of text is entered.

How can I have TextBox3 update only when tb1 or tb2 have finished changing?

+4  A: 

It depends a little on what you mean by finished.

The most common choice is to run an event when the focus leaves the control. That's the Control.Leave event or Control.LostFocus. These are also the events that are used for validation - validation of a new value (Validated and Validating events) takes place when the focus is changed.

If you're trying to do something like a progressive search, where you need to respond while the control is still in focus but not respond to every key press, then another solution is to use a Timer component, and restart the timer every time the TextChanged event is fired. This way, your update code will only be run after the user changes the text and hasn't typed anything else for, say, 1 second.

Aaronaught
A: 

I'm not exactly sure if this is what you are after, but DevExpress' editors control provides a buffered option which fires the change event after a user finishes typing (instead of after every keystroke)...this is basically what Aaronaught is suggesting with a Timer component...

http://documentation.devexpress.com/#WindowsForms/DevExpressXtraEditorsRepositoryRepositoryItem_EditValueChangedFiringModetopic

davidsleeps