从子窗口上的按钮单击事件更新主页上的列表框
本文关键字:更新 主页 事件 列表 按钮 窗口 单击 | 更新日期: 2023-09-27 18:33:42
我有一个包含列表框的主页。
当用户从列表框中选择配置文件时,这将打开一个名为 pWindow
的子窗口。此窗口作为通过超链接按钮删除当前配置文件的选项,该按钮打开另一个名为 dprofile
的确认窗口。
我的问题是,一旦用户确认删除他们所在的当前配置文件,并在按钮中确认dProfile
,我是否可以更新第一个主页中的listBox,以便列表不再包含已删除的配置文件(目前没有这样做。
在dProfile
窗口中,我创建了一个事件 -
public event EventHandler SubmitClicked;
在"确定"按钮中单击"我有-
private void OKButton_Click(object sender, RoutedEventArgs e)
{
if (SubmitClicked != null)
{
SubmitClicked(this, new EventArgs());
}
}
因此,在主页上我添加了-
private void deleteProfile_SubmitClicked(object sender, EventArgs e)
{
WebService.Service1SoapClient client = new WebService.Service1SoapClient();
listBox1.Items.Clear();
client.profileListCompleted += new EventHandler<profileListCompletedEventArgs>(client_profileListCompleted);
client.profileListAsync(ID);
}
我认为这可能已经更新了列表框,因为它在dProfile
表单中得到了确认,但是当表单关闭时,listBox 保持不变,我必须手动刷新网页才能看到更新。我该怎么做?
如果我理解正确,那么你有三页。Main、pWindow 和 dProfile。早些时候,您尝试从dProfile关闭pWindwow,并且工作正常。现在,您要刷新主页上的列表框1。
为此,您可以遵循类似的策略。您可能正在从主页打开 pWindow,并在以下行显示内容
pWindow pWin = new pWindow();
pWin.Show();
现在你可以在pWindow类中定义一个新事件。
public event EventHandler pWindowRefeshListBox;
然后在deleteProfile_SubmitClicked的事件处理程序中,您可以引发事件以刷新 listbox1,如下所示:
private void deleteProfile_SubmitClicked(object sender, EventArgs e)
{
if(pWindowRefreshListBox != null)
pWindowRefreshListBox(this, new EventArgs());
this.Close();
}
然后在主页中针对之前定义的 pWin 对象注册事件。
pWin.pWindowRefreshListBox += new new EventHandler(pWindow_pWindowRefreshListBox);
然后在主页中定义事件。
private void pWindow_pWindowRefreshListBox(object sender, EventArgs e)
{
listBox1.Items.Clear();
}
这应该刷新列表框。我还没有测试代码或语法。所以你可以检查一下在实施之前。
编辑
您可以在 dProfile 中将事件定义为静态
public static event EventHandler SubmitClicked;
然后,您将能够根据类名在主和pWindow中注册它
dProfile.SubmitClicked += new ..............
然后相应地实现它,在pWindow中,关闭窗口并在主刷新列表框中
编辑:
您可以在主页上创建删除配置文件的实例,在您的主页面中注册以下内容
deleteProfile.SubmitClicked += new EventHandler(deleteProfile _SubmitClicked)
这应该有效