• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

Search Item in a ListBox in VB.NET

lnjkgbejkkb

System Optimizer
L Rep
0
0
0
Rep
0
L Vouches
0
0
0
Vouches
0
Posts
68
Likes
15
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 100 XP
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:

searchdesign.png


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:

searchoutput1.png

searchoutput2.png


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


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,513

356,536

356,563

Top
Raidforums