• We just launched and are currently in beta. Join us as we build and grow the community.

How to Add the Items in the ListBox Using InputBox in VB.Net

bdblackmon

Memory Dump Analyst
Divine
B Rep
0
0
0
Rep
0
B Vouches
0
0
0
Vouches
0
Posts
81
Likes
79
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
In this tutorial I will teach you how to add the items in the ListBox in VB.Net. With this, you can type whatever data you want in the InputBox and it will be added in the ListBox. The InputBox has been just like a MessageBox, their only difference is that the InputBox has a TextBox that you can input the data.

Let’s begin:

Open the Visual Studio and create a new Project. Drag a Button and a ListBox. Then, do the Form just like this.

fist_form_inputbox.png


After that, double click the Button to fire the click

event handler.

Now, create a string variable to store the data that you have input and set the value on it.

  1. Dim

    inputdata As

    String

    =

    Nothing

Then, you have to create a constant variable to store a message on it and set it to its default message.

  1. Const

    msg As

    String

    =

    "Input data"

After that, you have to add the input data from the InputBox in the ListBox.

  1. ListBox1.

    Items

    .

    Add

    (

    InputBox

    (

    msg, "INPUT"

    , inputdata)

    )

Lastly, do this following code for clearing the data in the ListBox of the “Clear” Button.

  1. Private

    Sub

    Button2_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    Button2.

    Click
  2. 'CLEARING THE DATA IN THE LISTBOX
  3. ListBox1.

    Items

    .

    Clear

    (

    )
  4. End

    Sub

These are all the codes that we made.

  1. Public

    Class

    Form1
  2. Private

    Sub

    Button1_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    Button1.

    Click
  3. 'SET A STRING VARIABLE FOR THE DATA
  4. 'TO BE INPUT AND FOR THE MESSAGE OF THE INPUTBOX
  5. Dim

    inputdata As

    String

    =

    Nothing
  6. Const

    msg As

    String

    =

    "Input data"

  7. 'ADDING THE DATA IN THE LISTBOX THROUGH INPUTBOX
  8. ListBox1.

    Items

    .

    Add

    (

    InputBox

    (

    msg, "INPUT"

    , inputdata)

    )

  9. End

    Sub
  10. Private

    Sub

    Button2_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    Button2.

    Click
  11. 'CLEARING THE DATA IN THE LISTBOX
  12. ListBox1.

    Items

    .

    Clear

    (

    )
  13. End

    Sub
  14. End

    Class

 

452,158

323,328

323,337

Top