如何将列表视图作为参数传递 [英] how to pass list view as a parameter

查看:105
本文介绍了如何将列表视图作为参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以(用户来自)的一种形式拥有一个列表视图,并且它具有项的集合.我想将此列表视图作为参数传递给另一个方法,该方法存在于另一个类中

可以做到这一点还是不能做到?

I have a list view in one form in (user from), and it has collection of items. i want to pass this list view as a parameter to another method, this method exists on another class

can Do This Or Can''t ?

推荐答案

当然,这是可行的,有几种选择可以做到这一点.参见以下代码作为示例:
表格1:
Of course this is possible, there are several options to do that. See this code as an example:
Form1:
namespace WindowsFormsApplication1
{
   public partial class Form1 : Form
   {
      public Form1()
      {
         InitializeComponent();
         Form2 frm = new Form2();
         frm.DoStuffWithListView(listView1);
      }
   }
}


表格2:


Form2:

namespace WindowsFormsApplication1
{
   public partial class Form2 : Form
   {
      public Form2()
      {
         InitializeComponent();
      }

      public void DoStuffWithListView(ListView lst)
      {
         lst.Items.Add("Hello");
      }
   }
}


这篇关于如何将列表视图作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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