Refresh DataGridView in Windows Form

I have two forms, let it be form A and form B. When I click the save button on form B, I want to update the DataGridView of form A.

Which method to use?

+3
source share
3 answers

Using an event is one way to do this. The following is another object-oriented method.

Add a public update method to FormA.

public void RefreshDataGrid() { //Do refresh } 

Pass an instance of FormA to FormB when building FormB. You must create a FormB constructor to take an instance of FormA.

  private FormA myFormA; public FormB(FormA formA) { myFormA = formA; } 

Now you can call the FormA.ResfreshGrid () method from FormB.

 myFormA.RefreshGrid(); 
+5
source

implement code in form A as follows:

 private delegate void DEmpty(); public void RefreshDataGrid() { this.Invoke(new DEmpty(datagrid.Refresh)); } 

then call it when the button is pressed on B

+1
source

Create a gridview binding method, call this method when loading form A, and if the form is already open, you must use an instance of it (forms A) and call the same form A binding method to snap the grid.

0
source

All Articles