Click to See Complete Forum and Search --> : Question about the combo box


gibea00
December 13th, 2006, 10:32 AM
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

aniskhan
December 13th, 2006, 12:14 PM
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.

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 SubWhen dropDown then update the selectedItem to the new Value.
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