I'm trying to call a non-static method (LoadingListBox) in my class (ListDisplay) from a button click event in my AddTask class.
namespace Project
{
public partial class ListDisplay : Form
{
public void LoadingListBox()
{
//code
}
}
}
namespace Project
{
public partial class AddTask : Form
{
private void btnSubmit_Click(object sender, EventArgs e)
{
//code
//I want to call LoadingListBox here
}
}
}
I have tried creating an instance of ListDisplay
by doing ListDisplay listDisplayI = new ListDisplay();
and then writing ListDisplay.LoadingListBox();
There were no errors with this code but when debugging the flow of control wouldn't go to the method it just carried on past it. I have also tried doing what the answer suggests from this question:
Call a public method of main class from another class
But that comes up with an error as I can't overload the btnSubmit_Click method as the Designer freaked out. So I created a new method that had all of the code of btnSubmit_Click called public static void addingTask(ListDisplay)
but I then had to create an instance of ListDisplay in order to put it as an argument in the btnSubmit_Click method hence ending up with two instances which is not what I want (due to answer of question).
So now I have come up with nothing and would appreciate any help you could give in order to call this LoadingListBox method. Thanks!