Results 1 to 3 of 3

Thread: Selecting in listbox while user input being typed

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    69

    Resolved Selecting in listbox while user input being typed

    Hi all
    (using VB.NET 2005)
    The idea of the code below is to select the correct item from a listbox while the user types a name in a textbox. So if he Types "He" then the sub below is supposed to select the item in the itemlist that starts with "He" (well actually it doesnt start with "He" because the list consists of [projectnumber] [projectname], hence the split() ), it also makes the rest of the text selected. So if the name in the list is "Hennes" then "Hennes" would be copied to the textbox and "nnes" would be the selected text.

    VB Code:
    1. Private Sub txtProject_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtProject.KeyUp
    2.         Dim max As Integer = lstProject.Items.Count
    3.         Dim tempstr() As String
    4.         Dim i As Integer = 0  
    5.         Dim len As Integer = txtProsjekt.Text.Length
    6. [INDENT]While i < max
    7. [INDENT]tempstr = Split(lstProject.Items(i).ToString, vbTab)
    8. If tempstr(1).ToLower.StartsWith(txtProject.Text.ToLower) Then
    9. [INDENT]lstProject.SelectedIndex = i
    10. txtProject.Text = tempstr(1)
    11. txtProject.Select(len, 25)   'maximum length in this field is 25
    12. Exit Sub[/INDENT]End If
    13. i = i + 1[/INDENT]
    14. End While[/INDENT]
    15. End sub

    The code itself works very well as long as the user doesnt type too fast. And that is the problem i was hoping You could help me solve. The code doesnt work fast enough so if i type very fast the textbox would look like this:
    "Hennes e" (where i type "He"). I guess i could lock the textbox during the search, but that i think would only make the program seem slow.

    Any help here would be greatly appriciated!
    Last edited by Riks; May 2nd, 2006 at 09:08 AM.
    2B || !2B

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width