Click here to Skip to main content
15,914,452 members
Home / Discussions / C#
   

C#

 
AnswerRe: Network Transaction Management...... Need Help... Pin
Richard Andrew x6413-Jul-10 17:33
professionalRichard Andrew x6413-Jul-10 17:33 
GeneralRe: Network Transaction Management...... Need Help... Pin
nEar_mO13-Jul-10 17:40
nEar_mO13-Jul-10 17:40 
AnswerRe: Network Transaction Management...... Need Help... Pin
Peace ON13-Jul-10 19:49
Peace ON13-Jul-10 19:49 
QuestionTrigger a Parent Form Event From UserControl In TableLayoutPanel Pin
JessStuart13-Jul-10 14:32
JessStuart13-Jul-10 14:32 
AnswerRe: Trigger a Parent Form Event From UserControl In TableLayoutPanel Pin
Richard Blythe13-Jul-10 16:12
Richard Blythe13-Jul-10 16:12 
GeneralRe: Trigger a Parent Form Event From UserControl In TableLayoutPanel Pin
JessStuart14-Jul-10 6:51
JessStuart14-Jul-10 6:51 
GeneralRe: Trigger a Parent Form Event From UserControl In TableLayoutPanel Pin
Richard Blythe14-Jul-10 7:40
Richard Blythe14-Jul-10 7:40 
GeneralRe: Trigger a Parent Form Event From UserControl In TableLayoutPanel Pin
JessStuart14-Jul-10 8:07
JessStuart14-Jul-10 8:07 
Thanks for the encouragement.

Here's how I solved it, based on your example:

Relavant Main Form Code:

private void btnAddQuery_Click(object sender, EventArgs e)
{
    SQLXmlInterface newSxi = new SQLXmlInterface();
    newSxi.SaveButtonClicked += new System.EventHandler(SQLXmlInteface_SaveButtonHandler);
    sqlInterfaces.Add(newSxi);

    tlpQueries.Controls.Clear();
    foreach (SQLXmlInterface sxi in sqlInterfaces)
    {
        sxi.Refresh();
        tlpQueries.Controls.Add(sxi);
    }

    RefreshControls();
}

private void SQLXmlInteface_SaveButtonHandler(object sender, EventArgs e)
{
    RefreshControls();
}


Here's the relevant Dynamically Added Child Control Code:

public partial class SQLXmlInterface : UserControl
{
    SQLXmlObject sqlObject;
    bool saved = false;
    bool validated = true;
    public event EventHandler SaveButtonClicked;

    private void btnSave_Click(object sender, EventArgs e)
    {
        saved = true;
        sqlObject = new SQLXmlObject(txtTitle.Text, txtQuery.Text);
        RefreshControls();
        if (SaveButtonClicked != null)
            SaveButtonClicked(this, EventArgs.Empty);
    }
}



Synopsis (please correct if I've got it wrong):

The Main Form "listens" to the child control by the EventHandler assigned to the newSxi.SaveButtonClicked event.

The child object btnSave_Click event triggers (just calls, really) the SaveButtonClicked event.

Since the Main Form has the EventHandler defined for the SaveButtonClicked event, when the SaveButtonClicked event occurs, the EventHandler for the Main Form runs the SQLXmlInteface_SaveButtonHandler method, which was assigned to it in this code from the Main Form:

newSxi.SaveButtonClicked += new System.EventHandler(SQLXmlInteface_SaveButtonHandler);

GeneralRe: Trigger a Parent Form Event From UserControl In TableLayoutPanel Pin
Richard Blythe14-Jul-10 8:28
Richard Blythe14-Jul-10 8:28 
QuestionPlaying mp3 files?? Pin
Muammar©13-Jul-10 7:11
Muammar©13-Jul-10 7:11 
AnswerRe: Playing mp3 files?? Pin
I Believe In GOD13-Jul-10 7:39
I Believe In GOD13-Jul-10 7:39 
GeneralRe: Playing mp3 files?? Pin
Muammar©13-Jul-10 10:18
Muammar©13-Jul-10 10:18 
GeneralRe: Playing mp3 files?? Pin
Muammar©13-Jul-10 10:23
Muammar©13-Jul-10 10:23 
GeneralRe: Playing mp3 files?? Pin
harold aptroot13-Jul-10 10:38
harold aptroot13-Jul-10 10:38 
GeneralRe: Playing mp3 files?? Pin
Muammar©13-Jul-10 19:22
Muammar©13-Jul-10 19:22 
GeneralRe: Playing mp3 files?? Pin
Ravi Bhavnani13-Jul-10 11:43
professionalRavi Bhavnani13-Jul-10 11:43 
Questionsocket programming Pin
shaghyegh13-Jul-10 6:15
shaghyegh13-Jul-10 6:15 
AnswerRe: socket programming Pin
Abhinav S13-Jul-10 6:37
Abhinav S13-Jul-10 6:37 
QuestionHow to read attachment content using X-MS-ENUMATTS Method Pin
meeram39513-Jul-10 5:46
meeram39513-Jul-10 5:46 
QuestionMessage Removed Pin
13-Jul-10 5:40
Shahzad.Aslam13-Jul-10 5:40 
AnswerRe: Passing parameters from Other Application to .Net Pin
OriginalGriff13-Jul-10 5:45
mveOriginalGriff13-Jul-10 5:45 
GeneralMessage Removed Pin
13-Jul-10 6:25
Shahzad.Aslam13-Jul-10 6:25 
GeneralRe: Passing parameters from Other Application to .Net Pin
OriginalGriff13-Jul-10 8:10
mveOriginalGriff13-Jul-10 8:10 
GeneralRe: Passing parameters from Other Application to .Net Pin
Pete O'Hanlon13-Jul-10 10:00
mvePete O'Hanlon13-Jul-10 10:00 
GeneralRe: Passing parameters from Other Application to .Net Pin
OriginalGriff13-Jul-10 10:15
mveOriginalGriff13-Jul-10 10: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.