Link to home
Start Free TrialLog in
Avatar of Moshe Singer
Moshe SingerFlag for United States of America

asked on

How can I refer to a ComboBox by its string name?

How can I refer to a ComboBox by its string name?

ASKER CERTIFIED SOLUTION
Avatar of Kin Fat SZE
Kin Fat SZE
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Moshe Singer

ASKER

thanks a milion
i tried to use
Dim c As ComboBox =  Me.Controls("ComboBoxName")
this works fine

and then

c.Items.Clear()
Or
c.Items.Add(RsItm.Fields("itm").Value)
it givs a error
the exsact error masseg
Object reference not set to an instance of an object.
I checked, no error .
May be the Combox name is wrong?
Please check
i tested like this
I have mane combo boxes with the nama cmbo1, cmbo2 , cmbo3, cmbo4  
index have the number      
  Dim ComboStr As String = "cmbo" & index
        Dim c As ComboBox = Me.Controls(ComboStr)
        c.Items.Clear()

and it is making this error masseg
Object reference not set to an instance of an object.
I tried following code, that's working fine

Dim strNo As Integer = 1
Dim comboName As String = "ComboBox" & strNo
Dim c As ComboBox = Me.Controls(comboName)
c.Items.Clear()
c.Items.Add("abc")
1.    Private Sub cbo15_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbo15.Enter
2.       'Call CboEnFnc(15)
3.        Dim strNo As Integer = 15
4.        Dim comboName As String = "cbo" & strNo
5.        Dim c As ComboBox = Me.Controls(comboName)
6.        c.Items.Clear()    
7.        c.Items.Add("abc")
8.    End Sub
by line # 6
i get this error masseg   Object reference not set to an instance of an object.
maybe you have some refrence in the project thet helps