Click here to Skip to main content
15,894,106 members
Please Sign up or sign in to vote.
3.89/5 (2 votes)
See more:
Could someone please show me how to add text in textbox to listbox if both are on the same page? This is the code I tried myself:
MIDL
string temp ;
temp = txtData.Text;
lstDataList.Text += temp;
Posted
Updated 22-Sep-10 0:30am
v2
Comments
DavidKiryazi 22-Sep-10 9:29am    
Hi thabiso007,

Can I suggest you consider researching about some OOP concepts because from reading your code it seems evident you're unsure of the notion of "objects". This is a crucial and fundamental part of any OOP language like C# and without it you will find yourself making these same mistakes over and over just with different classes. :)

This code should do the trick:
lstDataList.Items.Add(txtData.Text);


However, you should really be careful about duplicate entries, as this code does not check for duplicate entries.
Hence,

if(lstDataList.Items.Contains(txtData.Text)==false)
{
   lstDataList.Items.Add(txtData.Text);
}
 
Share this answer
 
Try this:

lstDataList.Items.Add( txtData.Text );


Good luck!
 
Share this answer
 
Try This
String Str_temp ;
Str_temp = TxtData.text.tostring();
lst.items.add(Str_temp);



good Luck!!
 
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