事件保持空值 [英] Event keeps null value

查看:59
本文介绍了事件保持空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从子窗体到父窗体触发事件,但它保持空值。我有一个在子表单上声明的委托和事件,以及检查事件是否为空的方法。该方法在按钮单击时调用,并且应该通知父表单进行某些操作(刷新父表单上的网格数据。)



 < span class =code-comment> //  子表格 
public 部分 InventuraForm
{
public delegate void NekiDelegat();
public event NekiDelegat MojEvent;


public void SendEvent()
{
if (MojEvent!= null )MojEvent();
}

public void tsbSpremiZatvori_Click( object sender,EventArgs e)
{
// 一些代码

SendEvent();
}
}


// 父表单
public partial class InventuraFormPregled
{
InventuraForm _inv = null ;

public InventuraFormPregled()
{
InitializeComponent();

_inv = new InventuraForm();
_inv.MojEvent + = new InventuraForm.NekiDelegat(LoadGridData);

}

private void LoadGridData()
{
// 部分代码
}

}





任何帮助都是适用的。



< b>我尝试了什么:



我试图寻找类似的解决方案,但没有运气。

解决方案

您似乎已将其创建为一个非常简化的版本,它缺少大量信息。可能是重要的部分在冷凝过程中丢失了 - 当然代码不能像你自己描述的那样工作!

看看这个:在两种表格之间转移信息,第2部分:儿童到家长 [ ^ ] - 我知道这有效!

I am trying to fire event from child form to parent form but it keeps null value. I have a delegate and event declared on child form, and method that checks if event is not null. That method is called on button click and supposed to notify parent form for some action (refreshing grid data on parent form.)

//Child form
public partial class InventuraForm
{
    public delegate void NekiDelegat();
    public event NekiDelegat MojEvent;  


    public void SendEvent()
    {
        if (MojEvent != null) MojEvent();
    }

    public void tsbSpremiZatvori_Click(object sender, EventArgs e)
    {
       //some code

        SendEvent();
    }
}           


//Parent form
public partial class InventuraFormPregled 
{ 
    InventuraForm _inv = null;

  public InventuraFormPregled()
    {
        InitializeComponent();

        _inv = new InventuraForm();
        _inv.MojEvent += new InventuraForm.NekiDelegat(LoadGridData);          

    }     

 private void LoadGridData()
 {
 //some code
 }

}



Any help is appretiated.

What I have tried:

I tried to search for a similar solution, but no luck.

解决方案

You seem to have created this as a very simplified version, which is missing a load of information. It may be that the important parts have been lost in the "condensing" process - certainly that code is not going to work as you describe on it's own!
Have a look at this: Transferring information between two forms, Part 2: Child to Parent[^] - I know that works!


这篇关于事件保持空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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