Combo box search

I have a combobox named "combobox1". I am trying to search for a name in it. The search is working fine, however, in the combobox1.textbox my cursor always points to the first character place and thus the characters as i type keeping entering from the front. How can i edit this i am using th efollowing code.
        Dim AppPath As String = Mid(Application.ExecutablePath, 1, Len(Application.ExecutablePath) - 14)
        Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\Documen" & _
         "ts and Settings\My Documents\Database\Database.mdb"


        Dim dbConn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(strConn)
        dbConn.Open()
        Dim DSet As New DataSet, SQLStr As String
        Dim cmd As System.Data.OleDb.OleDbCommand
        Dim dbAdaptr As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
        Dim tRow As DataRow, tTbl As DataTable
        With dbAdaptr
            .TableMappings.Add("Table", "Doctors")
            SQLStr = "Select [Dfl] from Doctors ORDER BY Dfl"
            cmd = New System.Data.OleDb.OleDbCommand(SQLStr, dbConn)
            cmd.CommandType = CommandType.Text
            .SelectCommand = cmd
            .Fill(DSet)
            .Dispose()
        End With
        DSet.AcceptChanges()
        tTbl = DSet.Tables.Item(0)
        DSet.Dispose()
        dbConn.Close()


        ComboBox1.Items.Clear()
        ComboBox1.BeginUpdate()

        For Each tRow In tTbl.Rows
            '
            ComboBox1.Items.Add(tRow("Dfl").ToString)
        Next

        ComboBox1.EndUpdate()


        ' new method

        dv = New DataView(DSet.Tables("Doctors"))

        PopulateListBox(ComboBox1, dv)
        'PopulateListBox1(ComboBox1)
    End Sub


    Private Sub PopulateListBox(ByVal lb As ComboBox, ByVal dv As DataView)
        Dim i As Integer
        lb.Items.Clear()
        For i = 0 To dv.Count - 1
            lb.Items.Add(dv(i).Item(0))
        Next
        '   TextBox1.Text = lb.SelectedItem

    End Sub

    Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged


         dv.RowFilter = "dfl LIKE '" & ComboBox1.Text & "*'"
            PopulateListBox(ComboBox1, dv)
     
    End Sub
 
LVL 1
janjuama84Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DotNetLover_BaanCommented:
Add this line,  ComboBox1.SelectionStart = ComboBox1.Text.Length

    Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged


         dv.RowFilter = "dfl LIKE '" & ComboBox1.Text & "*'"
            PopulateListBox(ComboBox1, dv)

         ComboBox1.SelectionStart = ComboBox1.Text.Length
     
    End Sub

-Baan
janjuama84Author Commented:
It works good, one more question, how can i use the arrow keys, to select my result such that it appears in combobox.text and on pressing backspace i come back to the original list.?
DotNetLover_BaanCommented:
Not clear to me.
"to select my result"... what do you mean by that? Do you mean when you navigate through the list box, you want to see the selected items to be displayd in the combo box?
"pressing backspace"... do you want to do that when your cursor is in the combo box?
"i come back to the original list"... Do you mean you want to populate list box with out any filter?

-Baan
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

janjuama84Author Commented:
Its actually for example i have a list of names in the list. Example.

1. Albert
2. Henry
3. Ricky etc

If i type in "R" then only Ricky is left in the combobox as per my code. Thus i want to select the entry ricky and suppose if i delete the input "ricky" i come back to original list thus displaying all three names back again. However, if i want to keep the entry "ricky" then i want to select it so that i can use that as an entry for combobox1.text. The above code is able to generate the list, however, i am unable to select the result of my search and everytime i try to select it, the combobox1.text entry becomes empty.
DotNetLover_BaanCommented:
Well
you might need to trim your texts.

        For Each tRow In tTbl.Rows
            '
            ComboBox1.Items.Add(Trim("" & (tRow("Dfl").ToString))      'Changed this line
        Next

then.....

    Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged

         dv.RowFilter = "dfl LIKE '" & Trim("" & ComboBox1.Text) & "*'"    'Made changes here
            PopulateListBox(ComboBox1, dv)

         ComboBox1.SelectionStart = ComboBox1.Text.Length
     
    End Sub

Also change your SELECT statement little bit.
SQLStr = "Select LTrim(RTrim([Dfl])) from Doctors ORDER BY Dfl"   'Added LTrim & RTrim

-Baan

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DotNetLover_BaanCommented:
Haven't got any response from janjuama84 since my last comment.

-Baan
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.