How can I pass a value from a class to a Listbox

1

I am involved in a small personal project, composed of some classes and many forms. I need to send a value that is obtained when I access the given button, for the listbox that is in one of these forms. For this I chose to build a method called beverageclick with the following code

 public void beverageclick(object sender, EventArgs e)
        {
            Button b = (Button)sender;//button sender

        string value = (string)b.Tag;// value = b.tag (tag of sended button tag = value (value of  AddBeverageDrinkstoTabbedPanel) method)
        beverages.Add(value);
        //get value


        //MessageBox.Show(value);
        ListBox lstbox = new ListBox();
        lstbox.Items.Add(value);



        } 

How can I change the above code so that when I access a button, the value of that button (text) is inserted into the listbox.

    
asked by anonymous 03.03.2014 / 16:21

1 answer

2

You are creating a whole ListBox that made this button clicked. Add this value to a previously created listbox, drop ListBox lstbox = new ListBox(); . But if you want to create a ListBox every time the event is triggered, do not forget to put that listBox in a panel or something.

    
04.03.2014 / 00:35