Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have many value in listbox i want to pass all of them without selection in label that is in other form

What I have tried:

i have tried this but its shows only the value i chose

form1
C#
private void btn_voit_Click(object sender, EventArgs e)
        {
            string textboxchoix = listBox2.Text;           
            Form2 frm = new Form2(textboxchoix);
            frm.Show();
        }

form2 in label

C#
public Form2(string textboxchoix)
        {
            InitializeComponent();
           label_choix.Text = textboxchoix;
            
        }
Posted
Updated 17-Jan-17 2:36am
v3

The listbox maintains a collection of strings, while the label contains just one string.
If you wish to set the label text with the result of the concatenation of the listbox item strings then:
  • Build the 'concatenated string' by iterating over the listbox items.
  • Assign the concatenated string to your label text.
 
Share this answer
 
v2
Comments
ridoy 17-Jan-17 7:52am    
exactly, +5.
In first form use Session
ArrayList al = new ArrayList();
for (int i = 0; i < ListBox1.Items.Count; i++)
{
// if (ListBox1.Items[i].Selected == true)
// {
al.Add(ListBox1.Items[i].Value);
// }
}
Session["ListBoxItem"] = al;

and second form

lblResult.Text = "";

string[] products = (string[])Session["ListBoxItem"];

for (int i = 0; i < products.length; ++i)
{

lblResult.Text += products[i] + ",";

}
 
Share this answer
 
v2

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