Refresh DataGridView

Im working with MDI forms. I have two child forms 1 as a master & 2 as detail. The DataGridView is on Form1. When I make a change in form2 I would like to rebind or refresh the datagridView in Form1.


u2envy1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MortenSlotKristensenCommented:
You could do it like this:
TableAdapter.Fill
DataGridView.refresh();

It is likely that you also have to end edit if any has been commenced:
DataGridView.EndEdit();

Or you can refresh your bindingsource:
BindingSource.ResetBindings();

/Morten
0
u2envy1Author Commented:
That is not going to help if I refresh from another form.
This is what I have but im refreshing a different instance of Frm1
Frm1 frm1 = new Frm1 ();
frm1.dgvAppraisal.Dispose();
frm1.dgvAppraisal.Refresh();
0
MortenSlotKristensenCommented:
Yeah, you can't (directly) refresh a control on another form. I took a look at the following link which  talks about how do call methods from outside their creation thread:

http://msdn.microsoft.com/en-us/library/3s8xdz5c(VS.71).aspx

As it says: "The STA model requires that any methods on a control that need to be called from outside the control's creation thread must be marshaled to (executed on) the control's creation thread. The base class Control provides several methods (Invoke, BeginInvoke, and EndInvoke) for this purpose. Invoke makes synchronous method calls; BeginInvoke makes asynchronous method calls."

Hope this might help.
0
u2envy1Author Commented:
How do I use (Invoke, BeginInvoke, and EndInvoke)  with a frm1.dgvAppraisal.Refresh(); ?
Is their no way I can get the control form the current instance & not creating a new instance of the form ?
0
Anurag ThakurTechnical ManagerCommented:
use events and delegates to update datagrid on the first page when some data is updated from second page and you come back again on first page
have a look at the following
http://www.experts-exchange.com/Programming/Languages/.NET/Q_23671134.html
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_23736959.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.