Solved

search list box while typing characters in the text box

Posted on 2004-08-28
7
2,168 Views
Last Modified: 2013-12-03
I use VB.net

I have a Form with a text box and below it a lits box
I want to be able to narrow down the items in the list box as I type characters in the text box.
This si similar to  we see in windows help file
Can I buy a 3rd party control ( or does Microsoft provide this control in VB.net) or can I get a sample code some where on the web to achive this functionality?
or can you refer me to any web page that explains how to acomplish this.
Appreciate help
0
Comment
Question by:KumaraPrathipati
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 3

Accepted Solution

by:
imu79 earned 50 total points
ID: 11922366
Well..a simple way would be to just use the combobox. Set its style property to simple which will give you a textbox and a listbox beneath it. When you start typing the textbox, the listbox will scroll to the item that matches the typed text just as in the help files. However, there is one small problem: the matched item does not get selected as is done in the help file. I'm not sure how big of a problem that would be in your case.

hope this helps..
Imran.
0
 
LVL 3

Assisted Solution

by:GrumbleBot
GrumbleBot earned 50 total points
ID: 11923136
You could try something like this. This will search through the listbox as the text is changed in the text box. If the textbox text is equal to a substring of the listbox item then it will select it. So as you type more characters it will keep updating the selected item in the listbox.

If you want to actuall remove items from the list except those that match the current text then that will be a little different.

    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim i As Integer
        Dim s As String

        For i = 0 To ListBox1.Items.Count - 1
            s = ListBox1.Items(i)
            If String.Compare(s.Substring(0, textbox1.TextLength), TextBox1.Text) = 0 Then
                ListBox1.SelectedIndex = i
                TextBox1.Focus()
                Return
            End If

        Next
    End Sub


hope this helps.
Good luck
0
 
LVL 8

Assisted Solution

by:wguerram
wguerram earned 50 total points
ID: 11934114
This will give you the result you are looking for:

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim i As Integer

        With ListBox1
            i = .FindString(TextBox1.Text)
            If i >= 0 Then
                .SelectedItem = .Items(i)
            End If
        End With
    End Sub
0
 
LVL 8

Expert Comment

by:wguerram
ID: 11934127
instead of

.SelectedItem = .Items(i)

you can also use

.SelectedIndex = i
0
 
LVL 8

Expert Comment

by:wguerram
ID: 11934161
Also if do not want to keep the previous item selected when it is not found you have to add this

            If i >= 0 Then
                .SelectedIndex = i
            Else
                .SelectedIndex = -1
            End If
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to remove error in database 6 55
Broken .resx file generating errors 18 44
Call a VB.net function in Javascript 6 51
Suppress if value zero or NULL in crystal report 2 43
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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 …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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