使用委托传递数据. [英] Using delegate to pass data.

查看:116
本文介绍了使用委托传递数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想使用委托将日期从表单传递到另一个表单.这是代码:

Hi


I want to pass date from a form to another using delegate. This is the code :

public delegate void delEditareContact(ListViewItem text);
            delEditareContact nume = new delEditareContact(ec.NumeData);
            nume(this.LWContacte.Items[0]);


            delEditareContact nr_telefon = new delEditareContact(ec.NrTelefonData);
            nr_telefon(this.LWContacte.Items[0].SubItems[1]);



粗体字是问题..我想我不能传递listview的子项,只能传递项目..

请在这方面帮助我!


错误是:无法从"System.Windows.Forms.ListViewItem.ListViewSubItem"转换为"System.Windows.Forms.ListViewItem"



The bolded text is the problem.. I think i can''t pass a subitem of a listview, only items..

Please help me in this regard!


the error is: cannot convert from ''System.Windows.Forms.ListViewItem.ListViewSubItem'' to ''System.Windows.Forms.ListViewItem''

推荐答案

您得到的错误非常简单.更改委托以接受ListViewITem或传递this.LWContacte.Items[0]的值.

有什么问题?
The error you get is pretty straight forward. Either change the delegate to accept ListViewITem or pass the value of the this.LWContacte.Items[0].

What''s the problem?


您应该通过以下方法调用方法来传递ListViewItem:
You should either pass the ListViewItem by call the method in the following manner:
nr_telefon(this.LWContacte.Items[0]);



否则,您应该修改委托以接受类型为ListViewSubItem的参数:



Else you should modify the delegate to have accept a parameter of type ListViewSubItem:

public delegate void delEditareContact(ListViewSubItem text);


我找出原因..我必须为此类子项创建另一个委托:

公共委托void delEditareContactSubItem( ListViewItem.ListViewSubItem 文本);
I find out why .. I must create another delegate for the subitems like this:

public delegate void delEditareContactSubItem(ListViewItem.ListViewSubItem text);


这篇关于使用委托传递数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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