Filtering in ComboBox in VB.NET and SQL Server

1

I have a database in SQL Server and I am doing the inserts and updates to the database using the SQL Server syntax.

The request is, if someone can give me a code on how to filter a table at ComboBox and as the user typing the name, the concidences will show, just having one's code is enough for me, I only need to filter the name, because I have the last names in different fields.

    
asked by jairo giovany de la cruz marci 09.03.2016 в 06:04
source

1 answer

1

One option you have is to "bin" the combobox to the data in the table and in the combobox assign the properties: AutocompleteMode = Suggest and AutocompleteMode = ListItmes in this way the complete list will be loaded from the table to the control and it will be available for selection and will allow writing in the control and go receiving suggestions based on the written:

Public Class Form1

    Private Sub Form1_Load(Sender As Object, e As EventArgs) Handles Me.Load

        Dim ListaItems As New List(Of String)

        ListaItems.Add("Oveja")
        ListaItems.Add("Ornitorinco")
        ListaItems.Add("Toro")
        ListaItems.Add("Pato")
        ListaItems.Add("Tiranosaurio")
        ListaItems.Add("Piraña")

        Me.ComboBox1.DataSource = ListaItems
        Me.ComboBox1.AutoCompleteMode = AutoCompleteMode.Suggest
        Me.ComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems 


        ''' TODO: Reemplazar ListaItems por origen de datos

        ComboBox1.DataSource = ListaItems
        ComboBox1.AutoCompleteMode = AutoCompleteMode.Suggest
        ComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems

        Me.Controls.Add(ComboBox1)

        ComboBox1.Show

    End Sub

End Class
    
answered by 10.03.2016 в 02:59