0

I have a GridView in Liste_Form and button in Close_Form.

How can I refresh the Gridview in Liste_Form, when i click the button on Close_Form?

Or reload the Liste_Form.

John Arlen
  • 6,539
  • 2
  • 33
  • 42
user609511
  • 4,091
  • 12
  • 54
  • 86

2 Answers2

0

You have a few ways this can be done. One way I might suggest is passing a delegate to the second form in the constructor:

Form2 myForm2 = new Form2(RefreshGrid); // assign to a Form2 local variable

...where in Form1 (the grid owner) you have defined the RefreshGrid method:

void RefreshGrid(){
   // perform grid refresh
}

...so that in myForm2 you can execute the action when the button is clicked:

void OnButtonClicked(object sender, EventArgs e){
   refreshAction();
}
IAbstract
  • 19,551
  • 15
  • 98
  • 146
0

Define event on Close_Form (of course consider better name for event):

public event EventHandler SomethingHappened; 

Raise this event inside button click event handler:

private void Button_Click(object sender, EventArgs e)
{
    if (SomethingHappened != null)
        SomethingHappened(this, EventArgs.Empty);
}

Subscribe to this event on Liste_Form:

Close_Form closeForm = new Close_Form();
closeForm.SomethingHappened += Close_Form_SomethingHappened;

Refresh your list in this event handler:

private void Close_Form_SomethingHappened(object sender, EventArgs e)
{
    // refresh GridView
}
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459