control by name?

jiles

New member
Joined
Jan 4, 2012
Messages
2
Programming Experience
Beginner
my first post, hope I have the correct forum

I Need to add the same items to 20 dropdownlists at once, here is a simplified example

Private sub populatelist ()
Dropdownlistx.additem (“man u”)
Dropdownlistx.additem (“Chelsea”)
dropdownlistx.additem (“leeds”)

End sub



Dim x as integer
For x = 1 to 20

populatelist
next x


My problem is using the dropdownlistxIt don’t like mixing text and variable I tried
dropdownlist(x)
“dropdownlist” & x & “.additem”
tried dropdownlist[x]


is there a way to do this ?
many thanks in advance
 
What are you actually trying to achieve? The code you posted (if it worked) would just add those same items to the relevant dropdownlist 20 times.

Assuming you have the logic to create your listitems, you'd probably be better off defining your 'populate' method to accept a dropdownlist object and then work with that...so roughly :

VB.NET:
Sub Populate(ByRef myDropDownList as DropDownList)

...code to create myListItem(s)

myDropDownList.Items.Add(myListItem)

End Sub

Also, are you using DropDownLists or comboboxes? If you are using DropDownLists, you're in the wrong place, as they're web based.
 
hi, thanks for the reply
i am trying to achive 21 identical dropdownlists (3 per day 7 days a week)
its an online timesheet so for each task they complete, they choose a time value between 0.25 hour and 23.75 hour

so your suggestion

Sub Populate(ByRef myDropDownList as DropDownList)
..code to create myListItem(s)
myDropDownList.Items.Add(myListItem)
End Sub

would this go under an event for each dropdown list ?
can you show example for say dropdownlist 1 and 2 ?

thanks again
 

Latest posts

Back
Top