Searching Words In a ListBox in VB.Net
Today, I’m going to teach how to create a simple searching program in a listbox. It enables the user to search the nearest word and highlight the area where the item or word has been search.
So, Open your Visual Basic 2010 or 2013, and create a New Project.
Step 1:
Choose Visual Basic then Windows, Name your project as ‘Listbox’ and Click OK.
Add 1 Label, 1, TextBox, 1 Button and 1 ListBox.
In the Name Properties of Button and ListBox put the Name: btnSearch for Button and lstItem for ListBox. In the Text Property of Label and Button put the Search for Label and Button.
Step 2:
Copy and Paste the code
So, Open your Visual Basic 2010 or 2013, and create a New Project.
Step 1:
Choose Visual Basic then Windows, Name your project as ‘Listbox’ and Click OK.
Add 1 Label, 1, TextBox, 1 Button and 1 ListBox.
In the Name Properties of Button and ListBox put the Name: btnSearch for Button and lstItem for ListBox. In the Text Property of Label and Button put the Search for Label and Button.
Step 2:
Copy and Paste the code
Public Class Form1Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadWith lstItem.Items.Add("Hello World").Add("I am from Philippines").Add("I go to school").Add("I like programming using Visual Basic").Add("This tutorial shows you how to search a listbox").Add("Visit my blog: code-devs.blogspot.com")End WithEnd SubPrivate Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.ClickDim count As Integer = (lstItem.Items.Count - 1)Dim words As StringFor a = 0 To countwords = lstItem.Items.Item(a)If InStr(words.ToLower, TextBox1.Text.ToLower) ThenlstItem.SelectedItem = wordsEnd IfNextEnd SubEnd Class
Final Output:
Searching Words In a ListBox in VB.Net
Reviewed by code-dev
on
10:08 PM
Rating:
No comments: