从子窗口上的按钮单击事件更新主页上的listBox. [英] Update listBox on Main page from button click event on child window.

查看:97
本文介绍了从子窗口上的按钮单击事件更新主页上的listBox.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含列表框的主页.

I have a Main page that contains a listBox.

当用户从列表框中选择一个配置文件时,这将打开一个名为pWindow的子窗口. 此窗口是通过超链接按钮删除当前配置文件的选项,该按钮会打开另一个名为dprofile的确认窗口.

When a user selects a profile form the list box, this opens up a child window called pWindow. This window as the option to delete the current profile via a hyperlink button that opens up a another confirmation window called dprofile.

我的问题是,一旦用户确认删除他们所在的当前配置文件,并在按钮上单击dProfile确认了该配置文件,我该如何更新第一个主页上的listBox,以便列表不再包含已删除的配置文件(目前不这样做.

My question being is it possible that once a user has confirmed to delete the current profile they are in, and confirmed it in the button click on dProfile, how can I update the listBox in the first Main page so that the list no longer contains the deleted profile (which it is not doing at present.

dProfile窗口中,我创建了一个事件-

In the dProfile window I have created an event -

public event EventHandler SubmitClicked;

在确定"按钮中,单击我拥有"-

Where in the OK button click I have-

private void OKButton_Click(object sender, RoutedEventArgs e)
{
  if (SubmitClicked != null)
  {
      SubmitClicked(this, new EventArgs());
  }
}

因此在主页上我添加了

So on the Main page I have added-

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,但是当表单关闭时,listBox保持不变,我必须手动刷新网页才能看到更新.我该怎么办?

I thought this may have updated the listBox as it was confirmed in the dProfile form however when the form closes, the listBox stays the same and I have to manually refresh the webpage to see the update. How can I do this?

推荐答案

如果我正确理解它,那么您就有三页. Main,pWindow和dProfile. 更早,您正试图从dProfile关闭pWindwow,并且该窗口工作正常.现在,您要刷新主页上的listBox1.
为此,您可以遵循类似的策略.您可能正在主页上打开pWindow,并在下一行显示内容

If I understood it correctly then you have three pages. Main, pWindow and dProfile. Earlier you were trying to close pWindwow from dProfile and that was working properly. Now you want to refresh the listBox1 on Main Page.
To achieve that you may follow a similar strategy. You are probably opening pWindow from Main page with something on the following line

pWindow pWin = new pWindow();
pWin.Show();

现在您可以在pWindow类中定义一个新事件.

Now you may define a new event in pWindow class.

public event EventHandler pWindowRefeshListBox;

然后在事件处理程序中的deleteProfile_SubmitClicked中,您可以引发事件以刷新listbox1,如下一行所示:

Then in your event handler for deleteProfile_SubmitClicked you may raise the event to refresh listbox1, something on the following line:

private void deleteProfile_SubmitClicked(object sender, EventArgs e)
{
    if(pWindowRefreshListBox != null)
        pWindowRefreshListBox(this, new EventArgs());
    this.Close();
}

然后在您的主页中针对您先前定义的pWin对象注册事件.

Then in your main page register the event against pWin object, which you defined earlier.

pWin.pWindowRefreshListBox += new new EventHandler(pWindow_pWindowRefreshListBox);

然后在主页"中定义事件.

Then define the event in Main page.

private void pWindow_pWindowRefreshListBox(object sender, EventArgs e)
{
    listBox1.Items.Clear();
}

这应该刷新列表框.我没有测试代码或语法.所以你可以检查一下 在实施之前.

This should refresh the listbox. I haven't test the code or the syntax. So you may check it before implementing.

编辑
您可以在dProfile中将事件定义为静态

EDIT
you may define the event in dProfile as static

public static event EventHandler SubmitClicked;

然后,您将可以根据类名在Main和pWindow中注册它

Then you will be able to register it in Main and pWindow against Class Name

dProfile.SubmitClicked += new ..............

然后相应地在pWindow中实现它,关闭窗口并在主刷新列表框中

Then implement it accordingly, in pWindow, close the window and in main refresh listbox


您可以在主页上创建deleteProfile的实例,在您的主页中注册以下内容


You may create instance of deleteProfile on the main page register the following in your main

deleteProfile.SubmitClicked += new EventHandler(deleteProfile _SubmitClicked)

这应该有效

这篇关于从子窗口上的按钮单击事件更新主页上的listBox.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆