I'm a complete noob when it comes to .Net. I'm working on my college project.
In my application there's a combobox/drop-down list. My requirement is as soon as user starts typing inside it, i.e. when text_changed is triggered it should retrieve values starting from that letter from a column in the linked table. This should happend dynamically i.e. for different initial letters entries will be different so their index value should also be different each type.
I tried to write a code for very basic and statically populating entries but I'm not able to get it to work, will anyone please me?
Here's my code,

Private Sub ComboBox6_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox6.SelectedIndexChanged
        Dim sqlConn As SqlConnection
        Dim sqlCmd As SqlCommand
        Dim sqlDA As SqlDataAdapter
        'Dim sqlDS As SqlDataReader
        Dim ds As DataSet

        sqlConn = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=""F:\Swapnil\Documents\VS2010 Projects\Apex2\Apex2\Apex.mdf"";Integrated Security=True;Connect Timeout=30;User Instance=True")
        sqlCmd = New SqlCommand("select * from CustomerCode", sqlConn)
        sqlDA = New SqlDataAdapter(sqlCmd)
        ds = New DataSet()
        ComboBox6.Text = ds.Tables(0).Columns.ToString
        ComboBox6.ValueMember = ds.Tables(0).Columns.ToString

        ComboBox6.DataSource = ds.Tables

Why are you filling the ComboBox from the SelectedIndexChanged event? I would've used the Form_Load event to call a FillCombo() subroutine.

The ComboBox supports "TypeAhead" natively with the AutoCompleteMode & AutoCompleteSource properties. There is also a sample project here on CodeProject that fills that source from a DataTable, the code is in C# - but it will give you a good start.

You'll probably want to handle the ComboBox_Leave event to make sure the user doesn't add tables to your DB though... ;)

Edited 4 Years Ago by john.knapp

This article has been dead for over six months. Start a new discussion instead.