ComboBox Error? or Feature?

ahbenshaut

Well-known member
Joined
Oct 29, 2004
Messages
62
Location
Alaska
Programming Experience
5-10
Good day.
I have a combobox that is populated with a dataset. Right now, a user has to select a value in the combobox then click a button, but what they really want to do is start to type and have the value automatically fill in. Is that possible and how is it accomplished? One of the odd things is that even though I can type in a value in the combobox that is there, the value still has to be selected before anything can be done..
 
The .NET 2.0 ComboBox has autocomplete functionality built in, but in .NET 1.1 you would have to customise the ComboBox or use a third-party control.

It's quite simple to write code to select a matching value from the list yourself:
VB.NET:
Private Sub myComboBox.Leave(...) Handles myComboBox.Leave
    Dim currentText As String = myComboBox.Text.ToLower()

    For i As Integer = 0 To myComboBox.Items.Count - 1 Step 1
        If myComboBox.GetItemText(myComboBox.Items(i)).ToLower() = currentText Then
            myComboBox.SelectedIndex = i
            Exit For
        End If
    Next i
End Sub
I think that that will also happen automatically in .NET 2.0 if you're using the autocomplete feature.
 
Back
Top