Friday, April 4, 2014

Visual Basic Tutorial : How to Add/Remove Text on Listbox Using Textbox on Visual Basic (vb.net)



In this tutorial we are going to enter a text into the textbox and add it or it will display on listbox. The code we will be using is very simple line of codes. 

The code we will be using is this:

ListBox1.Items.Add(TextBox1.Text.Trim)
Step 1. Open MS Visual Basic
Step 2. Create New Project
Step 3. Add the following Controls

  • 1 listbox
  • 1 button
  • 1 textbox

Now that you have all these three controls, double click button1 then try to add the code above..


Note: We used the trim at the end of the code because it will tell the program to write new text into new line inside the textbox..


After typing the code, run the program and see if it works..


How to Remove Selected Text in Listbox

Removing text on listbox is easy as adding text to it, you only need a simple code to do this,..

We will use this code to perform that action....
ListBox1.Items.Remove(ListBox1.SelectedItem)
Before you do that, you need first to add new button into your project and change the "name" into "REMOVE SELECTED"

after doing that.. double click the button2 which is the remove button then add the following code provided above... 

Run you program and add text to it, then on the listbox select a text you want to remove then click remove selected.. and it will be removed..

Watch Video Tutorial



No comments:

Post a Comment