Search ListBox

Posted on 2006-04-05
Last Modified: 2010-04-24
Say I have a list box with over a 1000 items.  Is there an easy way to search a listbox?

So the search box is a textbox the user types in a word similar to what they are looking for...and the user clicks search...thus the listbox selects the closest word to the search word.  Is this possible or is it massive coding?


Question by:troyhalsey
    LVL 85

    Accepted Solution

    Try something like...

        Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            Dim index As Integer = ListBox1.FindString(TextBox1.Text)
            If index <> -1 Then
                ListBox1.SetSelected(index, True)
                ListBox1.TopIndex = index
            End If
        End Sub

    Author Comment

    Works great...only I changed:

    End If
    End Sub

    Because if I type in random gave an error...but now it just ignores the garbage.

    Thanks have been a big help today.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now