I have a windows form (a). On the form there is a search button that causes
another windows form (b) with a datagrid used to display the retrived data
from the SQL database. I would like to close form (a & b) when I select the
requested record. And reopen form (a) and display the selected record. I have
tried 'Owner.Close():'. The code thats used to call the search form (b)
follows:

private void btFind_Click(object sender, System.EventArgs e)
{
oclose = 1; // setup to do a close after the search is complete.
SearchOwner dddd = new SearchOwner(txtSearch.Text);
dddd.Show();
txtSearch.Text = string.Empty; // Clear the search field
}

Can someone give me some help thanks.

RE: Closing a form by tlkerns

tlkerns
Mon Apr 10 13:42:01 CDT 2006

Instead of all that, I would do it like this:

On form A in the search button click eventhandler, hide form A, then call
form b using ShowDialog. On form b, create a public property called
SelectedRecord that you set when the user selects a record. Then when form b
returns control to form A, just check the SelectedRecord property of form B,
retrieve the record, and show form A again.

This isn't everything, but it should get you going in the right direction.

Tony


"nbohana" wrote:

> I have a windows form (a). On the form there is a search button that causes
> another windows form (b) with a datagrid used to display the retrived data
> from the SQL database. I would like to close form (a & b) when I select the
> requested record. And reopen form (a) and display the selected record. I have
> tried 'Owner.Close():'. The code thats used to call the search form (b)
> follows:
>
> private void btFind_Click(object sender, System.EventArgs e)
> {
> oclose = 1; // setup to do a close after the search is complete.
> SearchOwner dddd = new SearchOwner(txtSearch.Text);
> dddd.Show();
> txtSearch.Text = string.Empty; // Clear the search field
> }
>
> Can someone give me some help thanks.