CallByName w/ComboBox

  • Thread starter Thread starter Timberwoof
  • Start date Start date
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
 
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
 
Back
Top