CallByName w/ComboBox

T

Timberwoof

For i = 1 To 3

CallByName(Form1.Controls("ComboBox" & i), "items.add", Type.Set, "1st item")
CallByName(Form1.Controls("ComboBox" & i), "items.add", Type.Set, "2nd item")
CallByName(Form1.Controls("ComboBox" & i), "items.add", Type.Set, "3rd item")
next

Is there a way I can populate these 3 combo boxes using the CallByName feature. My form has 3 combo boxes named ComboBox1, ComboBox2, ComboBox3.

I would really Prreeeeeeciate your help!

Timberwoof - ô¿ô


From http://www.developmentnow.com/g/38_2004_3_0_16_0/dotnet-languages-vb.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 
M

Mattias Sjögren

For i = 1 To 3
CallByName(Form1.Controls("ComboBox" & i), "items.add", Type.Set, "1st item")
CallByName(Form1.Controls("ComboBox" & i), "items.add", Type.Set, "2nd item")
CallByName(Form1.Controls("ComboBox" & i), "items.add", Type.Set, "3rd item")
next

Is there a way I can populate these 3 combo boxes using the CallByName feature. My form has 3 combo boxes named ComboBox1, ComboBox2, ComboBox3.

Any particular reason you want to use CallByName? If not, just do it
the strongly typed way

Dim combos() As ComboBox = {ComboBox1, ComboBox2, ComboBox3}
Dim items() As String = {"1st item", "2nd item", "3rd item"}
For Each c As ComboBox in combos
For Each s As String in items
c.Items.Add(s)
Next
Next


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