Solved

search as you type in vb.net

Posted on 2004-04-21
8
485 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
 

Author Comment

by:d3scr1pt0r
ID: 10887429
oh god, so easy..  thank you:))
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

758 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

19 Experts available now in Live!

Get 1:1 Help Now