Click here to Skip to main content
15,943,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a textBox in which items are entered.Each item is separated by #.

I want to get every item in listBox .

how to do that with a button click

C#
private void button1_Click(object sender, EventArgs e)
        {
            
        }
Posted
Updated 30-May-14 23:46pm
v2

First, split the string of the textbox. Then use the AddRange method to add all items to the listbox.
C#
private void button1_Click(object sender, EventArgs e)
{
    string[] items = yourTextBoxNameHere.Text.Split('#');
    yourListBoxNameHere.Items.AddRange(items);
}
 
Share this answer
 
Or
Determine your first array value for text or value. See the following code
protected void Button1_Click(object sender, EventArgs e)
   {
       string[] splitvalues = txtListvalues.Text.Split('#');
       ListBox1.Items.Add(new ListItem() { Value = splitvalues[0], Text = splitvalues[1] });
   }
 
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