get objekts

  • Thread starter Thread starter Abzieher Thomas
  • Start date Start date
A

Abzieher Thomas

hallo,


i hva got an form with ten textboxes
and now i want to set all text properties of each to "test"

is ther anpossibility to do this like this

for (i=0 ; i++, i>10)
setProp("text"+i.toStrin()", "text", "test");


thanks for your help
 
Abzieher,

No, you will at some point have to loop through and make the method call
yourself.

Hope this helps.
 
Abzieher Thomas said:
i hva got an form with ten textboxes
and now i want to set all text properties of each to "test"

is ther anpossibility to do this like this

for (i=0 ; i++, i>10)
setProp("text"+i.toStrin()", "text", "test");

You can use reflection if you really *have* to have that structure -
but it would be far better for your form to have a method which took
the text box number and the new value, and kept the textboxes
themselves in an array.
 
You can set the text property of every text box on a form to a string like
this:

foreach (Control control in this.Controls)
if (control is TextBox)
((TextBox)control).Text = "test";
 
Forms are parent controls, and therefore have a property called Controls
which is a ControlCollection (essentially a special array of controls) that
maintains a list of child controls within it. In order for a control to be a
child to a parent, it must be added to this collection. The form designer
will automatically generate this code for you when you drag a TextBox onto a
form, otherwise you must do it manually.

So! Every form automatically maintains a list of controls with in it (as do
panels, groupboxes, etc) and you can just use that. You can even single out
controls in the list by the Name or Tag properties or however else you'd
like to manipulate a subset of controls in the collection. I wrote code for
this elsewhere in the thread.
 
Actually, this won't work as a control can also have sub controls.
you must use Recursion to travel down the tree of contained controls

JIM
 
Back
Top