Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 ?
Posted
Comments
Sushil Mate 26-Sep-12 7:37am    
List View?? or you want to say the collection which you binds to that list view?

Collection you can pass as a parameter.
Anele Ngqandu 26-Sep-12 7:44am    
you want to pass all values in your list view or just the selected one?

1 solution

Of course this is possible, there are several options to do that. See this code as an example:
Form1:
C#
namespace WindowsFormsApplication1
{
   public partial class Form1 : Form
   {
      public Form1()
      {
         InitializeComponent();
         Form2 frm = new Form2();
         frm.DoStuffWithListView(listView1);
      }
   }
}

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

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900