1
votes

I have written this code to clear the items of a combobox

But the problem i am facing is when I select "a" from ComboBox1 then ComboBox2 displays "1","2"and "3" and suppose if I select "1" from ComboBox2 then next When I change the value of ComboBox1 to "b" then "4","5" and "6" are displayed in the drop down menu of ComboBox2 but the selected value in ComboBox2 remains as "1"

If ComboBox1.text="a" then
ComboBox2.items.clear()
ComboBox2.items.add("1")
ComboBox2.items.add("2")
ComboBox2.items.add("3")
ElseIf ComboBox1.text="b" then
ComboBox2.items.clear()
ComboBox2.items.add("4")
ComboBox2.items.add("5")
ComboBox2.items.add("6")
ElseIf ComboBox1.text="c" then
ComboBox2.items.clear()
ComboBox2.items.add("7")
ComboBox2.items.add("8")
ComboBox2.items.add("9")
Else
ComboBox2.items.clear()
End if
1
Actually what you want to do?sujith karivelil
I dont want to get displayed the value of ComboBox2 when I change ComboBox1Prudhvi Charan
Then why are you adding items after clear?sujith karivelil
change ComboBox2 selected index to -1currarpickt
I want items in the drop down menu of ComboBox2 but the value shouldn't be selected until the down arrow is clickedPrudhvi Charan

1 Answers

0
votes

I think what you are trying to do is change the contents of the box, and therefore the old selected item no longer makes any sense to be selected. As some of the comments have suggested, you still have the residual index selected. You need to reset the index (to -1) so that nothing is selected.

This should do the trick, by clearing the selected index (to no item selected) for each time the box contents are cleared/re-populated.

If ComboBox1.text="a" then
    ComboBox2.items.clear()
    ComboBox2.SelectedIndex = -1
    ComboBox2.items.add("1")
    ComboBox2.items.add("2")
    ComboBox2.items.add("3")
ElseIf ComboBox1.text="b" then
    ComboBox2.items.clear()
    ComboBox2.SelectedIndex = -1
    ComboBox2.items.add("4")
    ComboBox2.items.add("5")
    ComboBox2.items.add("6")
ElseIf ComboBox1.text="c" then
    ComboBox2.items.clear()
    ComboBox2.SelectedIndex = -1
    ComboBox2.items.add("7")
    ComboBox2.items.add("8")
    ComboBox2.items.add("9")
Else
    ComboBox2.items.clear()
    ComboBox2.SelectedIndex = -1
End If