Command button not working with MDI

Nov 22, 2013 at 2:00 PM
Hi everyone, I'm a bit new to C#, I'm trying to implement this ribbon to work with multi documents interface(MDI). I created a form where I included this ribbon and made the form an MDI container. This works fine and the forms(MDIChildren) Load smoothly without a problem.
The problem I have is when I use the save command button from the MDI Parent to save the contents of the Child form to SQL Database. It just can't save even though on another MDI form with the same situation the code works fine. The code is follows:

//In the Parent Form

TestForm tf = new TestForm(); //child object

private void btnSave_Click(object sender, EventArgs e)
    {
        Form Child0 = this.ActiveMdiChild as TestForm;
        if (Child0 != null)
        {
            try
            {
                tf.Save(); //call function Save in the Child Form
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Barcode Not updated", ex.Message);
            }
        }
    }
//IN THE CHILD FORM

public void Save()
    {
        this.Validate();
        this.productBindingSource.EndEdit();
        this.tableAdapterManager.UpdateAll(this.adventureWorks2012DataSet);

        MessageBox.Show("Data Saved");
    }

Am I making a mistake somewhere? please help,
Nov 23, 2013 at 9:15 AM
Edited Nov 23, 2013 at 9:15 AM
Try this and see what error message do you catch:
private void btnSave_Click(object sender, EventArgs e)
{
    try
    {
        Form Child0 = this.ActiveMdiChild as TestForm;
        if (Child0 != null)
        {
            try
            {
                tf.Save(); //call function Save in the Child Form
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Barcode Not updated", ex.Message);
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}
Nov 23, 2013 at 9:59 AM
It does not give any errors, it goes up to the end and show a message box with the message "Data Saved"
Nov 23, 2013 at 11:19 AM
I think the problem is not related to the Ribbon. Something is missing in these methods:
this.Validate();
this.productBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.adventureWorks2012DataSet);
As your code start from RibbonButton-Save_Click Event can reach this code:
MessageBox.Show("Data Saved");
Nov 23, 2013 at 12:46 PM
I thought so also, I then put a save button directly on the child form as follows

private void btnUpate_Click(object sender, EventArgs e)
{
Save();
}

to test the save code and it is saving without a problem. Then I created another mdi project with the same coding as in my first post. It works fine. I'm confused now. Should it be something to do with the ribbon or what am I missing?