Hey guys,
From a previous thread where I asked how I could update the view, saeidw suggested using Custom Events so I gave it a shot. Unfortunately, things did not go well. The following is the code I'm using:
FeedbackEvent class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HarbManager
{
class FeedbackEvent : EventArgs
{
public FeedbackEvent(string TextMessage)
{
Message = TextMessage;
}
public string Message { get; set; }
}
}
I then instantiated the this event class inside the AdminMain class using:
private event EventHandler<FeedbackEvent> Feedback;
and created the following method to raise the event:
private void RaiseEvent(string p)
{
EventHandler<FeedbackEvent> Handler = Feedback;
if (Handler != null)
{
Handler(this, new FeedbackEvent(p));
//I also tried Handler(null, new FeedbackEvent(p));
}
}
In the form_load event handler I subscribed to the Feedback handler:
Feedback += new EventHandler<FeedbackEvent>(UpdateView);
In the save_new_partner event handler I called the RaiseEvent() method passing a string. The UpdateView handler is as follows:
private void UpdateView(object sender, FeedbackEvent e)
{
MessageBox.Show("Custom Event Handling Is Working!", "Success!"); //for debugging purpose
this.AllPartners.Checked = true;
}
So what's wrong with my code?