Here is the child form:

Here’s the code behind it:
public partial class uxFormDatabase : Form
{
BindingSource rawtableBindingSource = null;
public uxFormDatabase(BindingSource myPassedSource)
{
InitializeComponent();
rawtableBindingSource = myPassedSource;
uxDGVtable.AutoSize = true;
dataToDGV();
}
public void dataToDGV()
{
uxrawdataBindingNavigator.BindingSource = this.rawtableBindingSource;
uxDGVtable.DataSource = this.rawtableBindingSource;
}
private void saveToolStripButton_Click(object sender, EventArgs e)
{
Validate();
rawtableBindingSource.EndEdit();
}
}
I was under the impression that when uxFormDatabase is activated the method public uxFormDatabase(BindingSource myPassedSource) fires which passes the BindingSource in from the parent form;
If that is the case then why when I press the save button ‘saveToolStripButton_Click’, on the BindingNavigator are the changes not getting saved back to the database? Do these two lines not save changes back to the databse Validate();rawtableBindingSource.EndEdit(); ?
UPDATE
The above form is loaded from this parent form:
namespace WindFormAppRevisionHelper
{
public partial class uxRevisionHelperForm : Form
{
public SqlCeConnection conn = null;
public SqlCeDataAdapter da = null;
public DataSet ds = null;
BindingSource definitionsBindingSource = new BindingSource();
public uxRevisionHelperForm()
{
InitializeComponent();
uxDescriptionTextBox.AutoSize = true;
refreshBindingSource();
assignControlsToSource();
}
public void refreshBindingSource()
{
conn = new SqlCeConnection(ConfigurationManager.ConnectionStrings["WindFormAppRevisionHelper.Properties.Settings.DefinitionsDBConnectionString"].ConnectionString);
da = new SqlCeDataAdapter(new SqlCeCommand("Select * From tb_RevisionDefinitions",conn));
ds = new DataSet("Study Helper");
ds.Tables.Add("DefinitionsTable");
da.Fill(ds.Tables["DefinitionsTable"]);
// Assign the BindingSource.
definitionsBindingSource.DataSource = ds.Tables["DefinitionsTable"];
uxBindingNavigator.BindingSource = this.definitionsBindingSource;
}
void assignControlsToSource()
{
uxDescriptionTextBox.DataBindings.Add(new Binding("Text", definitionsBindingSource, "Description", true));
uxWordPhraseTextBox.DataBindings.Add(new Binding("Text", definitionsBindingSource, "WordPhrase", true));
uxReferenceTextBox.DataBindings.Add(new Binding("Text", definitionsBindingSource, "Reference", true));
}
private void uxUpdateDataButton_Click(object sender, EventArgs e)
{
uxRevisionHelperGroupBox.Enabled = false;
uxBindingNavigator.Hide();
uxFormDatabase myNewDisplay = new uxFormDatabase(definitionsBindingSource);//<<<<this loads the _child_ form
myNewDisplay.FormClosed += delegate { activateGroupBorder(); };
myNewDisplay.Show();
}
public void activateGroupBorder()
{
uxRevisionHelperGroupBox.Enabled = true;
uxBindingNavigator.Show();
}
}
If you look at this example you can see that, the SqlDataAdapter object used to prepare the binding source, is responsible of the database update.
I think you could pass to the constructor of your
uxFormDatabasealso theSqlCeDataAdapter da, save it in a global instance var inside youruxFormDatabaseand then, after theValidateandEndEdit, callda.Update((DataTable)rawtableBindingSource.DataSource);Code used: