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
Solved

search as you type in vb.net

Posted on 2004-04-21
8
490 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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