Solved

search as you type in vb.net

Posted on 2004-04-21
8
495 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
[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
  • 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
Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

 

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

635 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