Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

search as you type in vb.net

Posted on 2004-04-21
8
Medium Priority
?
502 Views
Last Modified: 2007-12-19
Hi, all,

I use a textbox(TxtSearch) and a listbox(listbox1) .  I am populating the listbox from a dataset.
I want as the user types something, the most relative match to be highlighted in the listbox.
That is what I am trying for the last days with no luck :
________________________________________________________________
      Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Short, ByVal wParam As String, ByRef lParam As String) As Integer
     Const LB_FINDSTRING As Short = &H18FS


 Private Sub TxtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtSearch.TextChanged
        Dim txtsearch As Object
        Dim LB_FINDSTRING As Object
        Dim Listbox1 As Object
        Dim SendMessage As Object
Listbox1.selectedindex = SendMessage(Listbox1.handle, LB_FINDSTRING, txtsearch, txtsearch.Text)
    End Sub
________________________________________________________________________________
whenever I change something in the txtsearch_textchange i get all sorts of errors, there is no way to figure it out, this is one of the many codes i tried,  is there another way to do it, or am I doing a common error?
thanks:)
0
Comment
Question by:d3scr1pt0r
  • 4
  • 3
8 Comments
 
LVL 9

Expert Comment

by:malharone
ID: 10884094
0
 
LVL 3

Expert Comment

by:Lektran
ID: 10884782
Private Sub TxtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtSearch.TextChanged
       ListBox1.SelectedIndex =  ListBox1.FindString(TxtSearch.Text)
End Sub
0
 
LVL 3

Accepted Solution

by:
Lektran earned 320 total points
ID: 10884789
always check the available methods for the controls you are using before you start looking for hard ways to do things ;)
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

Author Comment

by:d3scr1pt0r
ID: 10887429
oh god, so easy..  thank you:))
0
 

Author Comment

by:d3scr1pt0r
ID: 10887470
what can I add, so that when I type something that is not contained, or differs from the value because there are more letters afters the ones matching,  in the listbox , so that i do not get :
Additional information: Object reference not set to an instance of an object.
?


(no points for this question, I gave enough for a simple thing i think :p
0
 
LVL 3

Expert Comment

by:Lektran
ID: 10887508
sorry, i guess i didnt give if the best answer if that happening

Private Sub TxtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtSearch.TextChanged
       Dim index as integer
       Dim index As Integer
       index = ListBox1.FindString(TextBox1.Text)
       If Not index = ListBox1.NoMatches Then
      ListBox1.SelectedIndex = index
       End If
End Sub
0
 
LVL 3

Expert Comment

by:Lektran
ID: 10887511
oops only one dim index required lol
0
 

Author Comment

by:d3scr1pt0r
ID: 10888435
now it just selects the first value whatever i enter:p
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

886 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