Technology Programming

How to Add a Textbox Value to a List in Visual Basic

    • 1). Open one of your Visual Basic projects using Visual Studio. Double-click the project's startup form. The Design window opens and displays the form.

    • 2). Click "View," and then click "Toolbox." The Toolbox window opens. Drag the ListBox control onto the form.

    • 3). Return to the Toolbox window. Drag a TextBox control and a Button control onto the form. Click the TextBox control you added to the form, and then press "F4" to view the Properties window. Find the name of the TextBox control at the top of the window. Write that name down.

    • 4). Return to the form and write down the name that appears in at the top of the ListBox control. That name is the ListBox control's name.

    • 5). Double-click the Button control you added to the form. The Code window opens and displays the Sub that runs when users click the button. Visual Studio positions your cursor inside this Sub automatically.

    • 6). Paste the following code into the Sub:

      ListBoxName.Items.Add(TextBoxNme.Text)

      Replace "ListBoxName" with the name of your ListBox control, and replace "TextBoxName" with the name of your TextBox control.

    • 7). Press "F5" to run the project. The form appears. Type a word into the TextBox control and click the Button control. The text appears in the ListBox control.

Leave a reply