The main form:
fDocForm fDocForm = new fDocForm()
fDocForm.ShowDialog();
if(fDocForm.DialogResult!=null)
//use of id returned from dialog form
else
MessageBox.Show("null");
in the dialog form:
private void button1_Click(object sender, EventArgs e)
{
//insert sql command and returned id of inserted recored
DialogResult = DialogResult.OK;
this.Hide();
}
how could I return the id value from the dialog form to the main form?
One option is to pass data from child form to parent form using an event which is invoked when clicking a button on the child form, data is in a validate state invoke the event then set DialogResult to OK.
The following is a conceptual example where the main form opens a child form for adding a new item of type Note.
If all you need is a single property/value this will still work by changing the delegate signature OnAddNote.
Note class
Operations class
NewNote method is called from the child form Add button when data is validated
Child form
Main form
Full source