Hia Yongkuy
Hia Yongkuy

Reputation: 79

Vb.net ComboBox Autocomplete

I have a ComboBox with DropDownStyle = Simple and have bound it to a DataSet. What I want is : when I type 'a', I want my ComboBox to show only the items starting with the letter 'a' just Dictionary Program.

I have tried the AutoComplete property but it just shows a DropDown and that's not what I want

HERE IS MY CODE:

Private Sub TICKETING_FORM_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        da.Fill(ds, "STYLE")
        bs.DataSource = ds.Tables("STYLE")

        With Style_ComboBox
            .DataSource = bs
            .DisplayMember = "STYLE"
            .ValueMember = "STYLE"
            .AutoCompleteMode = AutoCompleteMode.Suggest
            .AutoCompleteSource = AutoCompleteSource.ListItems
        End With

    End Sub

Upvotes: 4

Views: 59939

Answers (4)

Tuxmezoo
Tuxmezoo

Reputation: 11

The answers is quite simple. You load your combobox like you would normally by adding the display member and the value member. Then you load your autocomplete by the Display member and whala. Keep in mind that the auto complete function is basicly just a filter option on the display member side under normal conditions.

Here follows and example. Keep in mind that this example draws the list of names from our AD account and is nor shown here....

Dim col As New AutoCompleteStringCollection
Dim i As Integer
If Not MyUsers Is Nothing Then
    For i = 0 To MyUsers.Rows.Count - 1
        col.Add(MyUsers.Rows(i)("displayname").ToString)
    Next
    Request_ManagerComboBox.AutoCompleteSource = AutoCompleteSource.CustomSource
    Request_ManagerComboBox.AutoCompleteCustomSource = col
    Request_ManagerComboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend
    Request_ManagerComboBox.DisplayMember = MyUsers.Rows(i - 1)("displayname").ToString
    Request_ManagerComboBox.ValueMember = MyUsers.Rows(i - 1)("samAccountName").ToString
End If

Upvotes: 1

ømi
ømi

Reputation: 521

Private Sub TICKETING_FORM_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    da.Fill(ds, "STYLE")
    bs.DataSource = ds.Tables("STYLE")

    With Style_ComboBox
        .DataSource = bs
        .DisplayMember = "STYLE"
        .ValueMember = "STYLE"
        .AutoCompleteMode = AutoCompleteMode.SuggestAppend ' This is necessary
        .AutoCompleteSource = AutoCompleteSource.ListItems
    End With

End Sub

Upvotes: 4

Jade
Jade

Reputation: 2992

Change this Setting

DropDownStyle = DropDownList

Upvotes: 4

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28403

You need to set these property for AutoComplete

ComboBox1.AutoCompleteMode = AutoCompleteMode.Append
ComboBox1.DropDownStyle = ComboBoxStyle.DropDown
ComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems


Private Sub TICKETING_FORM_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        da.Fill(ds, "STYLE")
        bs.DataSource = ds.Tables("STYLE")

        With Style_ComboBox
            .DataSource = bs
            .DisplayMember = "STYLE"
            .ValueMember = "STYLE"
            .DropDownStyle = ComboBoxStyle.DropDown
            .AutoCompleteMode = AutoCompleteMode.Suggest
            .AutoCompleteSource = AutoCompleteSource.ListItems
        End With

    End Sub

Upvotes: 11

Related Questions