• 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.

Advertise Here

Advertise Here

Advertise Here

ListBox Adding and Removing an Item in VB.NET

normal2244

Active Directory Auditor
N Rep
0
0
0
Rep
0
N Vouches
0
0
0
Vouches
0
Posts
165
Likes
176
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
ListBox is a control that displays a collection of items. More than one item in a ListBox is visible at a time. You can either populate the ListBox control directly, or bind it to a collection of items.

In this tutorial, i will discuss some events in ListBox such as adding and removing an item in a ListBox.

So, 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 one TextBox named TextBox1 which will be used as an input for inputting the names of a school. Add one ListBox named ListBox1 which will be used as a container to display the inputted schools in TextBox1. Add also two Buttons named Button1 labeled "Add" for adding items in the ComboBox and Button2 labeled "Remove" for removing the selected item in the ListBox. You must design your layout like this:

lbdesign.png


3. Now, put this code in Button1_Click. This will trigger to add an item on the ListBox as we input a school in TextBox.
  1. Private

    Sub

    Button1_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    Button1.

    Click
  2. ListBox1.

    Items

    .

    Add

    (

    TextBox1.

    Text

    )
  3. TextBox1.

    Clear

    (

    )
  4. End

    Sub

Explanation:

For adding an item in the ListBox, we simply type this syntax ListBox1.

Items

.

Add

. The ListBox provides features that enable you to efficiently add items to the ListBox as we input a school on our TextBox. Then it will display the inputted string in our ListBox.

Output:

lbadd.png

lbaddview.png


4. Now add this code for Button2_Click. This will remove the item you have selected in the ListBox. Note that you must put first your cursor in your selected item in the ListBox.
  1. Private

    Sub

    Button2_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    Button2.

    Click
  2. ListBox1.

    Items

    .

    Remove

    (

    ListBox1.

    SelectedItem

    )
  3. TextBox1.

    Clear

    (

    )
  4. End

    Sub

Explanation:

For removing an item in the ListBox, we simply type this syntax ComboBox1.

Items

.

Remove

(

ListBox1.

SelectedItem

)

. The ListBox1.SelectedItem here was an action to select or click an item in the ComboBox before clicking the remove button.
Then it will clear the your TextBox.

Output:

lbremove.png

lbremoveview.png


Download the source code below and try it! :)

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number 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,500

350,639

350,649

Top