Padgey85
Padgey85

Reputation: 209

Send data from a listbox to a label on another form

I have a menu where I can add items to a list box using an add button.

I then have a button to send the order so to speak.

The button to send the order I need it to be able to send what is in the list box to a label (or even list box?) on another form.

So far I am only able to write my own text in a text box and then send it to a label on another form, I can't work out how to use what is in the list box to send to that label.

Upvotes: 0

Views: 620

Answers (1)

ian korkie
ian korkie

Reputation: 53

You can do it like this:

  • In your first form with the listbox

    Form2 f = new Form2(listBox1);
    f.Show();
    
  • In second form with label

    public Form2(ListBox listy)
    {
        InitializeComponent();
    
         foreach (var item in listy.Items)
         {
            label1.Text += item.ToString();
         }
     }
    

Upvotes: 1

Related Questions