Question about the combo box
HI !
I have some combo box in which the user cannot write. He has to pick an item in the list. How can i do that ?
In another combo box the user can chose an existing item in the list or write something else. Is it possible for me, in my code, to know if the user select an item in the list or write something in the combo box ?
Thanks for your help
Alexandre
Re: Question about the combo box
Q#1
Set dropDownStyle property to dropdownlist of combobox to allow the user to only select from dropdown list.
Q#2
Save the SelectedIndex when dropDown is Closed.
Code:
Private _itemIndex As Integer = -1
Private Sub ComboBox1_DropDownClosed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.DropDownClosed
_itemIndex = ComboBox1.SelectedIndex
End Sub
When dropDown then update the selectedItem to the new Value.
Code:
Private Sub ComboBox1_DropDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.DropDown
If _itemIndex <> -1 Then
ComboBox1.Items(_itemIndex) = ComboBox1.Text
End If
End Sub