I am trying to send information to a listbox to a Form from a class. Sounds simple enough. However it just won’t show anything after the method has run.
This is my Class and Method ‘Testclass’ that is being called from form one
public void testclass()
{
Form1 m = new Form1();
int tostng = "36183464";
m.listBox1.Items.Add(tostng).ToString();
}
in Form1 I have a listbox which has had it’s modifiers set to “Public” so not errors pop up. It will run but nothing will be entered into the listbox. This code works when everything is all in Form1.
Thank you for looking.
What you are doing is creating a new instance of the form – I presume you are trying to add items in a listbox on an existing form?
If so do this.
Create a function on the form with the listbox like:
Then, in the class (remember to add the using System.Windows.Forms reference)