1

Hi all i am doing an application in win forms

I am having a small issue i.e i am having my main form as

Tree view, panel and a data grid. I am having some user control forms.

When i select a node from tree view corresponding user control will be get loaded in the panel if main form. This works good.

Now for the child nodes i am having some text files attached when i click on that i will display the data grid along with the data present in the text file. This also works fine.

But now when click on data grid cells i would like to show the data in the user control form .

Can any one tell how to handle the controls from particular user controls that was displayed

1 Answer 1

3

The best approach is to use event-handlers as a publisher-subscriber paradigm. In your publisher you use public event EventHandler FlightStarted; and having a EventArgs class:

    public class StartEventArgs: EventArgs
    {
    public String flightCode { get; private set; }

    public StartEventArgs(String flightCode)
    {
        this.flightCode = flightCode;
    }

In your publisher class you use an OnSomething-method to fire off the event.

    public void OnFlightStarted(StartEventArgs e)
    {
        if (FlightStarted != null)
            FlightStarted(this, e);
    }

Now you need to have a subscriber as well:

flight.FlightStarted += new EventHandler(flight_FlightStarted);

and the method

    void flight_FlightLanded(object sender, EventArgs e)
    {
        if (e is LandEventArgs)
        {
            LandEventArgs landEventArgs = e as LandEventArgs;
            String flight = landEventArgs.flightCode;
            while (flight.Length <= 15)
                flight += " ";
            String time = DateTime.Now.ToLongTimeString();
            lbxStatus.Items.Insert(0, flight + "landed" 
                + "                 " + time);
        }
    }

More to read here: Event Tutorial C#

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.