3 Replies - 788 Views - Last Post: 27 September 2010 - 02:03 PM Rate Topic: -----

#1 Striker9099  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 19-October 09

Custom Events

Posted 24 September 2010 - 09:42 PM

Hey everyone,

I'm trying to refresh the view in my application whenever the user does certain stuff, so I decided to use Custom Events for this task. 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?

Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: Custom Events

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,546
  • Joined: 23-August 08

Re: Custom Events

Posted 24 September 2010 - 10:17 PM

Full custom events tutorial right here
Was This Post Helpful? 0
  • +
  • -

#3 Striker9099  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 19-October 09

Re: Custom Events

Posted 24 September 2010 - 11:23 PM

View PostJackOfAllTrades, on 24 September 2010 - 09:17 PM, said:


This is the tutorial I used before writing up my code... I donno what it's not working though.
Was This Post Helpful? 0
  • +
  • -

#4 Striker9099  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 19-October 09

Re: Custom Events

Posted 27 September 2010 - 02:03 PM

Anyone got any ideas?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1