c# - Create an Eventhandler via class -
I have an application with lots of ListBox controls. I was wondering if the listing holder for Anseleted Indix Will it be possible to add? All listboxes will use the same method for it
I know that I can manually add them but I was hoping for a solution that is currently being used by all those who use the same phenomenon People will change and when I add a new one, which does not tie the method.
Can you just iterate over the controls? For example (initiaize your form
'/ control
' in ctor):
CascadeListBoxEvent (this, MyHandlerMethod)
Using the utility method:
Fixed zero CascadeListBoxEvent (control parent, event, handler handler) {line & lt; Control & gt; Line = new line & lt; Control & gt; (); Queue.Enqueue (parent); While (queue number; gt; 0) {control c = queue.Dequeue (); ListBox lb = listbox; If (lab! = Null) {lb.SelectedIndexChanged + = Handler; } Foreach (control children in c.Controls) {queue.Enqueue (child); }}}
Comments
Post a Comment