Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextBox TextChanged event does not fire when Visible = False?

I have a textbox bound to a datasource. The textbox's TextChanged event updates another textbox.

The problem is, I do not want the first textbox to show, so I set its Visible property to false.

However, now the TextChanged event does not fire!

I can work around it by setting Visible=True, Left=-100000 on form load, but I'd like a proper solution.

Can anyone offer an explanation?

like image 974
Blorgbeard Avatar asked Dec 28 '22 13:12

Blorgbeard


2 Answers

Set your textbox.Visible = false in the FormLoad event instead of in the designer. It has to do with handle creation. If the textbox is not visible during construction, then the handle is not created. If the textbox is made invisible after construction, then the handle will have been created and events will occur.

See this discussion on MSDN.

like image 111
msergeant Avatar answered Feb 03 '23 14:02

msergeant


An alternative solution to the accepted answer is to set up the TextChanged listener on Loaded, this works for me just the same (in Silverlight at least) and keeps the designer view as it should be.

like image 40
dain Avatar answered Feb 03 '23 14:02

dain