views:

25

answers:

4

Hi,

I have a panel and in it are a couple of text boxes, I want to decide if to enable a button (also inside the panel) by the values of the the text boxes.

Is there a predefined event the panel is registered to that captures the inner text-boxes onTextChange event?

Thanks, Shuky

A: 

Unfortunately you have to do it yourself (subscribe to the event on the text boxes).

Grzenio
A: 

No, there isn't (AFAIK). But you can make all of your text boxes use call the same method when the event occurs. If you want to add text boxes dynamically, you might register for the ControlAdded event and in there in turn register on the freshly added textbox.

chiccodoro
A: 

Unlike in HTML DOM, events in WinForms are not propagated to containing elements, so you'll have to listen to all the events yourself.

Amnon
A: 

I'd just set up one generic TextBox_TextChanged Event handler that calls my Validate method and then link every TextBox to it, which could be done with a loop.

Maybe something like (not tested):

foreach (Control ctrl in container.Controls) { if (ctrl is TextBox) { ctrl.TextChanged += new System.EventHandler(TextBox_TextChanged); } }

ho1