Milanisius Milanisius - 9 days ago 4x
C# Question

How can I call a non-static method out of another class in C#?

The question itself sounds a bit nooby. To call a non static method from another class you have to use the current instance of the class. I tried to get the instance of the class with the method i want to call to the second class. I think I succeeded but it is still not working yet.

This one way how I tried to bring the instance to the second class:

arbeitsbearbeitung arbeitenbearbeitung = new arbeitsbearbeitung(arbeit);
arbeitenbearbeitung.Parent = this;

(out of Class 1)

And this is where I used it in class 2:

Form frm = (Form)this.Parent;

I also tried it with different ways like passing it as parameter; same result...

This is
in class 1:

public void updateGrid()

It tells me that Form does not contain a definition for

I must be dumb but I can't find my mistake.

Thinking and googling for 2 hours and still no clue.

I feel dumb now. Thank you for your help!


Form does not have an updateGrid method but your derived class does. You need to cast Parent to your class: MyForm frm = (MyForm)this.Parent;