Click here to Skip to main content
15,912,897 members
Home / Discussions / C#
   

C#

 
GeneralRe: access parent from a child control Pin
Nagy Vilmos20-May-09 22:52
professionalNagy Vilmos20-May-09 22:52 
GeneralRe: access parent from a child control Pin
musefan20-May-09 23:02
musefan20-May-09 23:02 
GeneralRe: access parent from a child control Pin
Nagy Vilmos20-May-09 23:45
professionalNagy Vilmos20-May-09 23:45 
GeneralRe: access parent from a child control Pin
musefan20-May-09 23:58
musefan20-May-09 23:58 
GeneralRe: access parent from a child control Pin
DaveyM6920-May-09 23:35
professionalDaveyM6920-May-09 23:35 
AnswerRe: access parent from a child control Pin
OriginalGriff21-May-09 0:24
mveOriginalGriff21-May-09 0:24 
GeneralRe: access parent from a child control Pin
DaveyM6921-May-09 1:09
professionalDaveyM6921-May-09 1:09 
GeneralRe: access parent from a child control Pin
OriginalGriff21-May-09 1:39
mveOriginalGriff21-May-09 1:39 
Sorry. (I feel really small, now)
Your comments are (as always) correct, so I modified it.

In the child form:

public partial class frmDetail : Form
    {
    // Signal file change happened
    public delegate void ChangeHandler(object sender, EventArgs e);
    public static event ChangeHandler Changed;

    protected virtual void OnChanged(EventArgs e)
       {
       ChangeHandler ch = Changed;
       if (ch != null)
          {
          ch(this, e);
          }
       }

    private void DoSomethingToChangeData()
       {
       OnChanged(null);
       }
    }


I am not sure a try - catch block would be a good idea: it's not an error to not have a handler, and the throw/catch will be slow. But that is just me.

In the main form:

public frmMain()
    {
    frmDetail.Change += new frmDetail.ChangeHandler(Changed);
    }

private void ChangeCards()
    {
    // Let him see the detail.
    // Link in his event so if it cahnges, we detect it.
    frmDetail fd = new frmDetail(currentDetail);
    fd.ShowDialog();
    }

//
// Fired when the file is changed at a lower level.
//
private void Changed(object sender, EventArgs e)
    {
    FileChanged = true;
    }


Better?

No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.

This message is made of fully recyclable Zeros and Ones

GeneralRe: access parent from a child control Pin
DaveyM6921-May-09 1:57
professionalDaveyM6921-May-09 1:57 
GeneralRe: access parent from a child control Pin
OriginalGriff21-May-09 2:04
mveOriginalGriff21-May-09 2:04 
AnswerRe: access parent from a child control Pin
Mahesh_Blr24-May-09 20:08
Mahesh_Blr24-May-09 20:08 
QuestionDatabase Connection: Leave Open or Open and Close each time Pin
Programm3r20-May-09 22:29
Programm3r20-May-09 22:29 
AnswerRe: Database Connection: Leave Open or Open and Close each time Pin
musefan20-May-09 22:35
musefan20-May-09 22:35 
QuestionRe: Database Connection: Leave Open or Open and Close each time Pin
Programm3r20-May-09 23:01
Programm3r20-May-09 23:01 
AnswerRe: Database Connection: Leave Open or Open and Close each time Pin
musefan20-May-09 23:09
musefan20-May-09 23:09 
GeneralRe: Database Connection: Leave Open or Open and Close each time Pin
Programm3r20-May-09 23:21
Programm3r20-May-09 23:21 
GeneralRe: Database Connection: Leave Open or Open and Close each time Pin
venom007-Jul-09 22:48
venom007-Jul-09 22:48 
GeneralRe: Database Connection: Leave Open or Open and Close each time Pin
musefan7-Jul-09 23:21
musefan7-Jul-09 23:21 
GeneralRe: Database Connection: Leave Open or Open and Close each time Pin
venom008-Jul-09 12:54
venom008-Jul-09 12:54 
AnswerRe: Database Connection: Leave Open or Open and Close each time Pin
J4amieC21-May-09 0:54
J4amieC21-May-09 0:54 
QuestionRe: Database Connection: Leave Open or Open and Close each time Pin
Programm3r21-May-09 2:31
Programm3r21-May-09 2:31 
AnswerRe: Database Connection: Leave Open or Open and Close each time Pin
J4amieC21-May-09 2:55
J4amieC21-May-09 2:55 
GeneralRe: Database Connection: Leave Open or Open and Close each time Pin
Programm3r21-May-09 3:15
Programm3r21-May-09 3:15 
GeneralRe: Database Connection: Leave Open or Open and Close each time Pin
Dave Kreskowiak21-May-09 4:11
mveDave Kreskowiak21-May-09 4:11 
Question.NET DashBoard Pin
AmmySA20-May-09 22:17
AmmySA20-May-09 22:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.