Solved

search as you type in vb.net

Posted on 2004-04-21
8
488 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 80 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

815 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