Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How do I set up a program to when a user enters something into a text box,click a button, then it shows up in a list box?

Improved Question:
Alright,that's been solved. That was only a small part of this,as when someone clicks an item in the list box(right now theres only one there,"example1",when they click it,it shows on the right the account name"example1",the User Name "potato" and password,"pickle". The example one was already set by me,but if someone adds a new item to the list box,how would I set it up to where they can also add a log in and password,to where if they click one that they added,that it will also show a username and password next to it?
Posted
Updated 7-Oct-12 8:18am
v2
Comments
Sandeep Mewara 7-Oct-12 13:24pm    
Insert the texted item into the list box in button click event?
Devin Halbert 7-Oct-12 13:26pm    
Wait so would this work?(lbx=List Box,tbx=Text Box)
lbxAccounts.SelectedItem = tbxNewAccountName.Text
Sandeep Mewara 7-Oct-12 13:30pm    
No it would not. You need to create a new item and then set the item as text data and then add the item to listbox.
[no name] 7-Oct-12 13:30pm    
http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.items.aspx
Devin Halbert 7-Oct-12 13:32pm    
You must be a pc god,you have answered 3 of my 3 questions I have asked :D

Follow the following coding:

C#
lbx.Items.Add(tbx.Text);


Add the above code in your button's click event.
 
Share this answer
 
Try this code:
VB
Private Sub button1_Click(sender As Object, e As EventArgs)
    listBox1.Items.Add(textBox1.Text)
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900