By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

C# refreshing Datagridview from a different form

P: n/a
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..?

Apr 22 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Apr 21, 10:34 pm, rome...@gmail.com wrote:
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!

Apr 22 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.