Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1136
  • Last Modified:

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.


0
u2envy1
Asked:
u2envy1
  • 2
  • 2
1 Solution
 
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now