Open modal form

  • Thread starter Thread starter Mark Goldin
  • Start date Start date
M

Mark Goldin

I'd like to open a new modal form when I click on a button on my main form.
That new form will have a datagrid. When the user selects a row in the grids
I want to close
the form and get back to main form with information about user's selection.
What would basic technique be?

Thanks
 
On the selected row changed event of the grid, set the DialogResult property
of the modal form to DialogResult.OK. Once you set the DialogResult, the
form will dissappear. If the user closes the form without picking the row
by hitting the x or a cancel button, the form will use DialogResult.Cancel
for the DialogResult.

private void OnSomeRowEvent(object sender, EventArgs e) {
// set some property on the form for which row was selected
SomeProperty = grid.therow;
// set the dialog result
this.DialogResult = DialogResult.OK;
}

Then where you are launching the form you would have some code like this

MyModalForm modal = new MyModalForm();
if (modal.ShowDialog(this) == DialogResult.OK) {
// process for when the user clicked the row
// use the property on the form to get the info you want
}

Hope that helps!

Seth Wenzel
 
Back
Top