0

I have two forms in my project. One is named formOptions and another is formHome. I have a listBox in formOption named Blacklist. I have a textBox by which I can add text to the "Blacklist" listBox. Now, I want to access the items from "Blacklist" listBox from formHome. I have tried the following approach :

private void formHome_Load(object sender, EventArgs e)
{
    formOptions.Blacklist // as follows 
}

But at this point it shows an error that "An object reference is required for the non-static field, method, or property 'formOptions.Blacklist'.

Now, What can I do to access the listBox?

Rubel Hosen
  • 37
  • 1
  • 1
  • 5

2 Answers2

0

You can see here how to make instance of a form (fromOpition) on formHome.

Hellz Yeahh
  • 63
  • 1
  • 5
0

By studying this example code, you can get help:

//this code written in form1
Form2 form2 = new Form2();  //Form2 is my second Form
foreach(Control control in form2.Controls)
{
    if(control.GetType()==typeof(ListBox))  //you can put any typeof object
    {
        ((ListBox)control).Items.Add("HELLO"); 
        break;
    }
}
form2.ShowDialog();