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

C#

 
Answeraccess parent from a child control [modified] Pin
Mahesh_Blr20-May-09 22:33
Mahesh_Blr20-May-09 22:33 
AnswerRe: access parent from a child control Pin
musefan20-May-09 22:41
musefan20-May-09 22:41 
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 
I agree with all of them! Use option 3.

If this is your first time doing this, then you may need more detail:

In your child form:

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

    private void DoSomethingToChangeData()
       {
       OnChange(file, null);
       }
    }

In your main form:

public frmMain()
    {
    frmDetail.OnChange += new frmDetail.OnChangeHandler(OnChanged);
    }

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 OnChanged(object sender, EventArgs e)
    {
    FileChanged = true;
    }


It is pretty simple when you get your head around it!

[edit] Changed to move add event handler out of frmDetail instance create - we don't want another event each time ChangeCards is called, do we? My brain is not working - it must be thursday [/edit]

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:09
professionalDaveyM6921-May-09 1:09 
GeneralRe: access parent from a child control Pin
OriginalGriff21-May-09 1:39
mveOriginalGriff21-May-09 1:39 
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 

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.