0

GridView在 Liste_Form 中有一个按钮,在 Close_Form 中有一个按钮。

当我单击 Close_Form 上的按钮时,如何刷新GridviewListe_Form 中的内容?

或者重新加载 Liste_Form。

4

2 回答 2

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
}
于 2012-05-10T15:31:42.840 回答
0

你有几种方法可以做到这一点。我可能建议的一种方法是将委托传递给构造函数中的第二种形式:

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

...您在 Form1(网格所有者)中定义了RefreshGrid方法:

void RefreshGrid(){
   // perform grid refresh
}

...这样myForm2您就可以在单击按钮时执行操作:

void OnButtonClicked(object sender, EventArgs e){
   refreshAction();
}
于 2012-05-10T15:18:34.280 回答