Sign in to follow this  
Followers 0

[vb] How To Add Item To A Listbox

1 post in this topic

Requirements: Visual Basic(of course), Listbox control, textbox and command button

Listbox is where the item will go, Textbox is the item text and command button to add it to the list

Under the textboxes Change event add

Private Sub textboxname_Change()
   If Text1.Text = "" Then
       Command1.Enabled = False
       Command1.Enabled = True
   End If
End Sub

If Text1.Text = "" Then <== This is saying if theres no text in the textbox then it will make the command button disabled

Under the Command button Click event

Private Sub Command1_Click()
   List1.AddItem Text1.Text
End Sub

List1.AddItem Text1.Text <== Simply means add item to the list with the text in the textbox

Simple :)


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.