Hi guys.
What I'm trying to do is pass all items and subitems from a listview on my main form to a listview on a new form.
After googling for a couple of hours the closest I got was the the code below which only passes the selected Item from my main form to the new form, but I can't figure out how to send all of them.
I can see that this >> "Main_Form_ListView.FocusedItem.Clone(); }" is where I'm getting stuck but can't work out what I need to change it to.

Main Form

public MainForm()
        {
            InitializeComponent();
        }
        public ListViewItem _MainForm_Listview
        {
            get { return (ListViewItem)Main_Form_ListView.FocusedItem.Clone(); }
        }
        private void MainForm_Load(object sender, EventArgs e)
        {
            ListViewItem item = Main_Form_ListView.Items.Add("First");
            item.SubItems.Add("First");

            ListViewItem item2 = Main_Form_ListView.Items.Add("Second");
            item2.SubItems.Add("Second");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SecondForm SecondForm = new SecondForm(this);
            SecondForm._listView = _MainForm_Listview;
            SecondForm.ShowDialog();
            SecondForm.Dispose();
        }
    }

Second Form

public SecondForm(MainForm parentForm)
        {
            InitializeComponent();
        }
        public ListViewItem _listView
        {
            set
            { Second_Form_ListView.Items.Add(value); }
        }
    }

What do I need to change so that it passes ALL Items/Subitems to the listview on the second form.

Never mind.. got it.

Main form

public partial class MainForm : Form
    {
        private SecondForm clientFrm;
        public MainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            clientFrm = new SecondForm();
            clientFrm.Show();
            clientFrm.UpdateListView(this.listView1);
        }

        private void Server_Load(object sender, EventArgs e)
        {
            ListViewItem item = listView1.Items.Add("First Item");
            item.SubItems.Add("First SubItem");

            ListViewItem item2 = listView1.Items.Add("Second Item");
            item2.SubItems.Add("Second SubItem");
        }
    }

Second Form

public partial class SecondForm : Form
    {
        public SecondForm()
        {
            InitializeComponent();
        }
        public void UpdateListView(ListView listView)
        {
            foreach (ListViewItem item in listView.Items)
            {
                this.listView1.Items.Add((ListViewItem)item.Clone());
            }
        }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.