Hi everybody,
I am currently working on a C# project, but I am kind of stuck. If anybody can give me a hand with this I would really appreciate it.
We are trying to build an application with a user GUI. When I click button1 I want to call another method to do some work and when it is done, it should callback via a delegate. Unfortunately it is giving me the error “Object reference not set to an instance of an object.”. This should not be too complicated, but somehow I am not able to resolve this myself.
This is my code:
=== BEGIN GUI CODE ===
- public delegate void ButtonsServerTreeViewDelegate(object sender);
-
private void button1_Click(object sender, EventArgs e)
-
{
// Setup listener, for updating the GUI...
-
DiscTreeView DiscTreeViewObject = new DiscTreeView();
-
DiscTreeViewObject.ButtonsServerTreeView += new ButtonsServerTreeViewDelegate(CallbackButtonsServerTreeView);
-
-
// DiscTreeViewObject.LoadServerTreeView();
-
PathSelectionTreeView.LoadServerTreeView();}
-
-
public void CallbackButtonsServerTreeView(object sender)
-
{
label31.Text = "HI";
}
=== END GUI CODE ===
==== BEGIN OTHER CLASS CODE ====
- public event ButtonsServerTreeViewDelegate ButtonsServerTreeView;
-
public void LoadServerTreeView()
-
{
ButtonsServerTreeView(this);
}
==== END OTHER CLASS CODE ====
Note that the LoadServerTreeView is called with PathSelectionTreeView and not with the DiscTreeViewObject (commented out), since PathSelectionTreeView contains my TreeView.
Is there anyway to perform the callback, if I call my LoadServerTreeView via PathSelectionTreeView ?
Again, any help is greatly appreciated.
Warm Regards,
Jan