How to change the name of multiple textboxes

  • Thread starter Thread starter Jan
  • Start date Start date
J

Jan

Hi there,

I have a lot of textboxes in a form, i numberd them from from 1 til 10.

for example: txtZpr1.text
txtZpr2.text etc..

I want to fill these textboxes by using a loop.

Is there a way to fill them by changing the number of the textbox??

TIA Jan




--------------= Posted using GrabIt =----------------
------= Binary Usenet downloading made easy =---------
-= Get GrabIt for free from http://www.shemes.com/ =-
 
Hi there,

I have a lot of textboxes in a form, i numberd them from from 1 til 10.

for example: txtZpr1.text
txtZpr2.text etc..

I want to fill these textboxes by using a loop.

Is there a way to fill them by changing the number of the textbox??

TIA Jan

for I as integer = 0 to 10
dim txt as TextBox = CType(Me.Controls("txtZpr" & I.ToString()),
TextBox)
txt.Text = "New Text"
Next
 
Hi there,

I have a lot of textboxes in a form, i numberd them from from 1 til 10.

for example: txtZpr1.text
txtZpr2.text etc..

I want to fill these textboxes by using a loop.

Is there a way to fill them by changing the number of the textbox??

TIA Jan

--------------= Posted using GrabIt =----------------
------= Binary Usenet downloading made easy =---------
-= Get GrabIt for free fromhttp://www.shemes.com/ =-

You can use reflection to get all the controls of the form, of your
interest, and then set any property / invoke any member on those
controls. Google this for the syntax, which is easy enough to be
understood.

Thanks,
coolCoder
 
Jan said:
I have a lot of textboxes in a form, i numberd them from from 1 til 10.
for example: txtZpr1.text, txtZpr2.text etc..

I want to fill these textboxes by using a loop.

Is there a way to fill them by changing the number of the textbox??

Yes, there is.

But don't.

Visual Basic may not have VB's Control Arrays but, instead, you can have
Arrays of Controls:

Dim allmyTextBoxes As TextBox() _
= {txtZpr1, txtZpr2, ... txtZpr10}

For Each tb as TextBox in allmyTextBoxes
tb.Text = tb.Name
Next

HTH,
Phill W.
 
exact,

Just to show that it is as well my favorite which I learned from an answer
from Armin by the way,

:-)

Cor
 
Back
Top