hi,

i really don't know what exactly it is called :P , but i'll try to be clear on what i need.

i have a text box and a listbox. when the text box get focus, it loads the listbox and displays the content. What i need my code to do is, when i type something in the textbox, the LIKE words from the listbox gets highlighted. AND most importantly, when the user hit the 'down arrow key' from the from the keyboard i want the focus to shift to listbox AND with another key press (maybe enter key or something) the selected item from listbox get selected and displays in textbox.

Is this possible to achieve? or is it too much coding for newbie like me.

My texbox on focus code.

Private Sub txtItem_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtItem.GotFocus
        Try
            Dim ds As New DataSet
            Dim cmd As New OleDbCommand
            Dim da As OleDbDataAdapter = Nothing
            cmd.Connection = con
            cmd.CommandText = "Select typeID,type From subtype"
            da = New OleDbDataAdapter(cmd)
            da.Fill(ds, "type")
           With ListBox1
                .DataSource = ds.Tables("type") 
                .DisplayMember = "type"
                .ValueMember = "typeID"
                .SelectedIndex = 0
           End With
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try
    End Sub

if i'm too far behind from what i need, can someone please points me into the right direction. I know the above code has nothing to do with what i need as yet :P, as a matter of fact, i'v been VB-ing for only about 2 weeks. guidance will be highly appreciated :)

I figured out a few of my problems like when the user hit the 'down arrow key' from the from the keyboard i want the focus to shift to listbox AND with another key press (maybe enter key or something) the selected item from listbox get selected and displays in textbox VB has a neat little thing called KeyDown

Private Sub txtItem_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtItem.KeyDown
        ListBox1.Focus()
    End Sub

And to capture enter key

Private Sub ListBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown
        Select Case e.KeyCode
            Case Keys.Enter
                txtQuantity.Focus()
      End Select
    End Sub

Now my question is narrowed down to the selecting the %LIKE from listbox and bold it.
for eg:
listbox contains
1. Apple
2. Africa
3. Australia
4. Afghanistan

when user type 'A' all the four get selected(and bold) and with 'AF' only 2,4 is bold and the rest normal.

By the way, my Listitems are derived from database ... if that makes any difference.

What you can do is execute another LIKE statement against the database based on the characters entered in the text box and populate the list with the result. Then you only have the relevant LIKE items remaining. Items that don't meet the criteria are removed.

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