textboxes created at runtime

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?
 
T

Tim Wilson

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.
 
M

Mattias Sjögren

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top