Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

control arrays

Status
Not open for further replies.

Bvisual

Programmer
Jul 1, 2005
35
0
0
BE
how do you make arrays of components:
textboxes
optionrounds
buttons
...

i need like 50 small buttons but the caption on these buttons needs to be loaded from a productlist

the most easy way i believe to do this is (like in vb 6.0)
making a control array.

but i dont now how to do this execly in vb.net

how does this work, a little example would be great

thx
 
vb.net do not support any more control arrays.
You can add the button in a container, like a panel. Loop through each one and change the caption (in .net is called Text)

Dim c as control
for each c in me.panel1.controls
if typeof c is textbox then 'change the text only at textboxs
c.text=...
end if
next

or (better),
If the names of the buttons are: b0,b1,b2,b3 ... and
as you have the texts of the buttons in the list:

dim i as integer
for i=0 to listproducts.items.count
ctype("b" & i , Textbox).Text=listproducts.items.item(i)
next

 
or (better),
If the names of the <b>buttons</b> are: b0,b1,b2,b3 ... and
as you have the texts of the buttons in the list:

dim i as integer
for i=0 to listproducts.items.count
ctype("b" & i , <b>Textbox</b>).Text=listproducts.items.item(i)
next


is this code good, because it doesnot work????
for buttons that is

but this code would do the trik

how make it work????
 
Hi,

me again:

Code:
      Dim c As Button
      Dim lastDigit As Integer

      For Each c In Me.Panel1.Controls
         lastDigit = CType(c.Name.Substring(c.Name.Length - 1), Integer)
         c.Text = ListBox1.Items.Item(lastDigit)
      Next


Assume that:
- You have some buttons in Panel1
- Their names are: Button0, Button1, Button2 ...
- For e.g. Button0 you want to set its text to whatever is in ListBox1 at Index 0.


Post again for firther explanation
 
One correction:

lastDigit = CType(c.Name.Substring(6), Integer)

6 is the lenght of "Button", so with the Substring(6) i get the next chars:
E.g "Button123".SubString(6) gives "123"

If you change this STABLE prefix, make sure to change the number. So If the buttons' names start with "btnMyButton" then the number is 11.


Hope ths helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top