Moshe Singer
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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").Valu e)
it givs a error
Dim c As ComboBox = Me.Controls("ComboBoxName"
this works fine
and then
c.Items.Clear()
Or
c.Items.Add(RsItm.Fields("
it givs a error
ASKER
the exsact error masseg
Object reference not set to an instance of an object.
Object reference not set to an instance of an object.
I checked, no error .
May be the Combox name is wrong?
Please check
May be the Combox name is wrong?
Please check
ASKER
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 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")
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")
ASKER
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
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
ASKER