C# refreshing Datagridview from a different form

R

romerve

Hello; i am having some problems trying to get a form that has a
datagridview to refresh after a new record is created.

I have a MDI container and menu form and add new record form; the menu
form display the data using a data grid view and the add record form
creates an object and passes that data to a class method which creates
the record using sqlcommand.

The add new record form is loaded after the user clicks on the add
button on the menu form, from there the user enters all the data
required, but once the user is done and clicks on Ok, the new record
is created, but the datagrid has to be refreshed and thats where i am
having problems.

I would think that the refresh() method would be called right after
the connection close() method or before, but since the datagrid is
located on a different form, the add record form cant see the
datagridview in order to call the refresh() method...

Any thoughts on how to refresh a datagridview located on form1 from a
different form...?

thanks..?
 
G

gregarican

Hello; i am having some problems trying to get a form that has a
datagridview to refresh after a new record is created.

I have a MDI container and menu form and add new record form; the menu
form display the data using a data grid view and the add record form
creates an object and passes that data to a class method which creates
the record using sqlcommand.

The add new record form is loaded after the user clicks on the add
button on the menu form, from there the user enters all the data
required, but once the user is done and clicks on Ok, the new record
is created, but the datagrid has to be refreshed and thats where i am
having problems.

I would think that the refresh() method would be called right after
the connection close() method or before, but since the datagrid is
located on a different form, the add record form cant see the
datagridview in order to call the refresh() method...

Any thoughts on how to refresh a datagridview located on form1 from a
different form...?

thanks..?

I ran into a similar situation. What I did had the parent from being
the one containing the DataGridView. Then a child form would open
where I would add/change one of the DataRows. When I went to commit
the change I wanted the parent form to have its DataGridView refreshed
to reflect the add/change in the child form. What I did was pass the
parent form's DataTable (that its DataGridView is based on) into of
the child form through an initialization parameter. This way it had a
reference point. Then when the child form did its thing I would use a
TableAdapter in the child form to invoke its Fill method to refresh
the DataTable that was passed in from the parent form. Not sure if
this is necessarily the preferred way of doing this, but it worked for
me!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top