I am trying to update a SQL databound combobox with new information from a new form. After I make the adds/edits and save on the popup form, I want to refresh the combobox with the new info and select the currently added/edited item. Currently, the code below refreshes the list, but will not modify "myID" on the parent form as I thought a reference variable should. How can I most efficiently do this? I have about 20 forms to do a similar type thing.
In form1
int newid = 0;
private void addToolStripMenuItem1_Click(object sender, EventArgs e)
{
CoalSeamsForm csf = new CoalSeamsForm(ref newid);
csf.ShowDialog();
coalSeamsTableAdapter.Fill(well_Information2DataSet.CoalSeams);
coalSeamsBindingSource.Find("CoalSeamID", newid);
}
In form 2
int myID = 0;
public CoalSeamsForm(ref int myId)
{
this.myID = myId;
InitializeComponent();
}
private void CoalSeamsForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (!isOK)
{
if (DialogResult.Yes == MessageBox.Show("Would you like to save the changes?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
{
Save();
DataRowView drv = (DataRowView)coalSeamsBindingSource.Current;
myID = (int)drv["CoalSeamID"];
}
}
}
}