textboxes created at runtime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

building a form in c# which creates several controls at runtime. Since I
can't reference them at design time (since they haven't been created yet) Is
there a quick way to use reflection to itereate through a collection of all
the controls on that form and find (and then perform operations) the
textboxes created?
 
You don't need to use reflection to do this. You just need to recursively
iterate over the controls collection of the form. There is an example at the
link below that you can adapt to perform actions on all textboxes on the
form.
http://groups.google.com/group/micr...ework.windowsforms/msg/1d4e8bbdc567691f?hl=en

If, however, you are accessing all the textboxes frequently, or you intend
to access only the dynamically created textboxes as opposed to all
textboxes, you may consider storing the references to the controls in an
array for faster access.
 
building a form in c# which creates several controls at runtime. Since I
can't reference them at design time (since they haven't been created yet) Is
there a quick way to use reflection to itereate through a collection of all
the controls on that form and find (and then perform operations) the
textboxes created?

You don't need reflection, you can just recursively iterate the
Controls collection on the form and all container controls. But if
you're creating the textboxes, surely you can store references to them
in an array or other appropriate collection and get them directly from
there.


Mattias
 
Back
Top