how to search and highlight items in a listbox?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#0000ff; font-size:small <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; line-height:19px Hi
All
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#0000ff; font-size:small <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; line-height:19px Im
trying to search and higlight items of a listbox (using the snippet here below). Whats wrong with this code?
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
Option Strict On<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt; color:blue
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt; color:blue Imports<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt System.Data
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt; color:blue Imports<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt System.Data.SqlClient
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left

<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left

<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt; color:blue Public<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Class <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#2b91af Form1
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Private <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Sub Form1_Load(sender <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue As System.<span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#2b91af Object,
e <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue As System.<span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#2b91af EventArgs) <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Handles <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue MyBase.Load
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Dim con <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue As <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue New <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#2b91af SqlConnection
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt con.ConnectionString = <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#a31515 "Data
Source=.SQLEXPRESS;AttachDbFilename=C:Users.......DB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Dim adapter <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue As <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue New <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#2b91af SqlDataAdapter(<span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#a31515 "SELECT
table FROM field", con)
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Dim dt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue As <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue New <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#2b91af DataTable(<span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#a31515 "fielddt")
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span lang="FR" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt adapter.Fill(dt)
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="FR" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt ListBox1.DataSource = dt
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt ListBox1.ValueMember = <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#a31515 "field"
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt ListBox1.DisplayMember = <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#a31515 "field"
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue End <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Sub
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left

<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Private <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Sub Button1_Click(sender <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue As System.<span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#2b91af Object,
e <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue As System.<span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#2b91af EventArgs) <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Handles Button1.Click
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Dim MatchFound <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue As <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Boolean = <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue False
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Dim I <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue As <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Integer =
0
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Do
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue If InStr(ListBox1.Items(I).ToString,
TextBox1.Text, <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:#2b91af CompareMethod.Text) > 0 <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Then
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt MatchFound = <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue True
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt ListBox1.SelectedIndex = I
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue End <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue If
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt I += 1
<span style="white-space:pre Loop Until I > CInt(MatchFound)
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue If <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Not MatchFound <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Then
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt ListBox1.SelectedIndex = -1
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue End <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue If
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span lang="EN-GB" style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue End <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Sub
<p style="border:none; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; padding-right:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<span style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt; color:blue End<span style="border:0px; font-style:inherit; font-family:Consolas; margin:0px; outline:0px; padding:0px; font-size:9.5pt <span style="border:0px; font-style:inherit; font-family:inherit; margin:0px; outline:0px; padding:0px; color:blue Class

View the full article
 
Back
Top