65.9K
CodeProject is changing. Read more.
Home

Data-bound Auto Complete Combo

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (12 votes)

Mar 19, 2004

viewsIcon

81378

downloadIcon

395

A data-bound auto complete combo that filter items as you type.

Sample Image - DBAutoCompleteCombo.jpg

Introduction

This is a .NET auto complete combo-box component that binds to a dataset and filters combo items as you type, selecting the most similar item but showing other relatives items in the drop-down list.

Using the component

Right-click the toolbar, select add/remove itens and browse for the AutoCompleteComboBox.dll. Drag the component to the form as a normal combo-box.

Setting the data source

Use AddDataSource(DataTable,DisplayMember,ValueMember) method to set the combo data source.

Dim wDataSet As New DataSet
   
wDataSet.ReadXml("data.xml")

AutoCompleteComboBox1.AddDataSource(wDataSet.Tables(0), "UserName", "UserID")

The submit event

When enter is pressed in the combo, an event "submit" is raised. The example code shows the selected text and selected value when the user press enter.

Private Sub AutoCompleteComboBox1_Submit(ByVal sender As System.Object,_
 ByVal e As System.EventArgs) Handles AutoCompleteComboBox1.Submit

        Dim wComboValue As String = "(New Item)"

        If Not IsNothing(AutoCompleteComboBox1.SelectedValue) Then
           wComboValue = AutoCompleteComboBox1.SelectedValue
        End If

        lbInfo.Text = "Combo Item Text: " & _
    AutoCompleteComboBox1.SelectedText.ToString() & vbCrLf & _
    "Combo Item Code: " & wComboValue

    End Sub