用户控件中的DataGridview C#.net中的事件问题 [英] DataGridview in User Control Event issue in C#.net

查看:65
本文介绍了用户控件中的DataGridview C#.net中的事件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我正致力于用户控制。在该用户COntrol中,我想从表单中添加一些新事件以进行访问(父表单)。

我为CellClicked和CellDoubleClick添加了新事件。

这里代码,

  //  声明 
public delegate void CellClickedEventHandler(< span class =code-keyword> object sender,DataGridViewCellEventArgs e);
public event CellClickedEventHandler CellClicked;

public delegate void CellDoubleClickedEventHandler( object sender,DataGridViewCellEventArgs e);
public event CellDoubleClickedEventHandler CellDoubleClicked;


// 函数
私有 void CellClick(对象发​​件人,DataGridViewCellEventArgs e)
{
if (CellClicked!= null
CellClicked(< span class =code-keyword> this ,e);
}

私有 void CellDouClick( object sender,DataGridViewCellEventArgs e)
{
if (CellDoubleClicked!= null
CellDoubleClicked( this ,e);
}



在构造函数上:

< datagridview name =   >  .CellClick + =  new  DataGridViewCellEventHandler(CellClicked); 
< datagridview name = > ; .CellDoubleClick + = new DataGridViewCellEventHandler(CellDoubleClicked);



重建应用程序。错误列表中没有显示错误



拖动用户控件(Datagridview),我收到以下错误。

引用:

委托实例方法不能为空'this'



如何解决这个问题?

解决方案

http ://stackoverflow.com/questions/3752824/delegate-to-an-instance-method-cannot-have-null-this [ ^ ]

试试此链接。

Dear All,
I am working on user Control. In that user COntrol , I want to add Some New events for access from the form(Parent form).
I added New Events for CellClicked and CellDoubleClick.
Here the Code,

//Declaration 
 public delegate void CellClickedEventHandler(object sender, DataGridViewCellEventArgs e);
 public event CellClickedEventHandler CellClicked;

 public delegate void CellDoubleClickedEventHandler(object sender, DataGridViewCellEventArgs e);
 public event CellDoubleClickedEventHandler CellDoubleClicked;


//Functions
  private void CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (CellClicked != null)
                CellClicked(this, e);
        } 

  private void CellDouClick(object sender, DataGridViewCellEventArgs e)
        {
            if (CellDoubleClicked != null)
                CellDoubleClicked(this, e);
        }


On the Constructor:

<datagridview name="">.CellClick += new DataGridViewCellEventHandler(CellClicked);
<datagridview name="">.CellDoubleClick += new DataGridViewCellEventHandler(CellDoubleClicked);


Rebuild the application. no error displayed on the Error List

Drag the User Control(Datagridview), I am getting following error.

Quote:

Delegate to an instance method cannot have null 'this'


How can i solve this?

解决方案

http://stackoverflow.com/questions/3752824/delegate-to-an-instance-method-cannot-have-null-this[^]
Try this link.


这篇关于用户控件中的DataGridview C#.net中的事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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