Search Item in a ListBox in VB.NET

This tutorial provides to create a program that can search an item inside a ListBox in vb.net. Now, let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add only two Buttons named Button1 and labeled it as "Add Item" for adding an item from the textbox and displayed in ListBox and Button2 labeled as "Search Item" for searching an item in the ListBox. Insert a textbox named TextBox1 and ListBox named ListBox1. You must design your interface like this: design 3. For button1_click as Add Item button, put this code below.
  1. ListBox1.Items.Add(TextBox1.Text)
  2. TextBox1.Clear()
The code above gets the inputted string of the textbox to be added in the listview as we have the Items.Add function of the ListBox. After adding the item to the listbox, the textbox will now be cleared. 4. For button2_click as Search Item button, put this code below. Initialized a variable named index as an integer and input as a string.
  1. Dim index As Integer
  2. Dim input As String
Use variable input as an InputBox.  input = InputBox("Enter an item to search:") Use variable input as an InputBox.  index = ListBox1.FindString(input) Create an If Else statement that the index will not be equal to the Items inside of the ListBox and will display "Item is found". Otherwise display "Item not found!"
  1. If index <> ListBox.NoMatches Then
  2. MsgBox("Item is found!")
  3. Else
  4. MsgBox("Item not found!")
  5. End If

Output:

outputoutput Download the source code below and try it! :) For more inquiries just contact my number or e-mail below. Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Comments

Submitted byRana Arslan (not verified)on Thu, 10/23/2014 - 03:01

This is very helpful for me i am very thank full to you.

Add new comment