ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

Adding Items in the ListBox Using InputBox in VB.Net

In this tutorial, I’m going to teach you how to add the items in the ListBox using an InputBox in VB.Net. The InputBox is like a MessageBox, their only difference is that, it has a TextBox that you can input the data in it. With this, the data that you have typed in the text box of the InputBox will be added in the ListBox.

 

Let’s begin:

 

Open the Visual Studio and create a new Windows Form Application. Drag a Button and a ListBox and set the Form just like this.
inputboxform
After setting up the Form, double click the Button to fire the click event handler.
Create a string variable for storing data and set the initial value in it.

  1. Dim input_data As String = ""

Now, you have to create a constant variable and set the default message of it.

<vbnet] Const message As String = “Data Entry”
[/vbnet] After that, add the data that you have input in the InputBox to the ListBox.

  1. ListBox1.Items.Add(InputBox(message, "Input", input_data))

Lastly, for clearing data in the ListBox, you have to put this code in the click event handler 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 you have made.

  1. Public Class Form1
  2.  
  3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4. 'SET A STRING VARIABLE FOR THE DATA
  5. 'TO BE INPUT AND FOR THE MESSAGE OF THE INPUTBOX
  6. Dim input_data As String = ""
  7. Const message As String = "Data Entry"
  8.  
  9. 'ADDING THE DATA IN THE LISTBOX THROUGH INPUTBOX
  10. ListBox1.Items.Add(InputBox(message, "Input", input_data))
  11.  
  12. End Sub
  13.  
  14. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  15. 'CLEARING THE DATA IN THE LISTBOX
  16. ListBox1.Items.Clear()
  17. End Sub
  18. End Class
Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!