Click here to Skip to main content
14,327,370 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello,

I have many tabcontrols,on every tabcontrol there are 2 Listviewcontrol with data. When I click on any TabControl, i want to pass data of 2 listview on this tabcontrol to 2 external listview. How can i do it? Pls, someone can help me!
Posted
Comments
Michael_Davies 29-Jul-15 4:28am
   
Trap the Selected event for the tab or the SelectedIndexChanged for the tabcontrol and process accordingly...
Ramza360 29-Jul-15 10:05am
   
Sounds like the right answer to me!
Jordy K 30-Jul-15 2:25am
   
Do you have example codes?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Please try some thing like this , I am not sure from question you mean the same :


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

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

        private void Form1_Load(object sender, EventArgs e)
        {
           tabPage1listView1.Items.Add("Tab1ListView1Item1");
           tabPage1listView1.Items.Add("Tab1ListView1Item2");
           tabPage1listView1.Items.Add("Tab1ListView1Item3");

           tabPage1listView2.Items.Add("Tab1ListView2Item1");
           tabPage1listView2.Items.Add("Tab1ListView2Item2");
           tabPage1listView2.Items.Add("Tab1ListView2Item3");

           tabPage2listView1.Items.Add("Tab2ListView1Item1");
           tabPage2listView1.Items.Add("Tab2ListView1Item2");
           tabPage2listView1.Items.Add("Tab2ListView1Item3");

           tabPage2listView2.Items.Add("Tab2ListView2Item1");
           tabPage2listView2.Items.Add("Tab2ListView2Item2");
           tabPage2listView2.Items.Add("Tab2ListView2Item3");

           tabPage3listView1.Items.Add("Tab3ListView1Item1");
           tabPage3listView1.Items.Add("Tab3ListView1Item2");
           tabPage3listView1.Items.Add("Tab3ListView1Item3");

           tabPage3listView2.Items.Add("Tab3ListView2Item1");
           tabPage3listView2.Items.Add("Tab3ListView2Item2");
           tabPage3listView2.Items.Add("Tab3ListView2Item3");

           tabControl1.SelectedIndex = 1;
           tabControl1.SelectedIndex = 0;
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            TabControl Tabctrl = (TabControl)sender;

            string SelectedTab= Tabctrl.SelectedTab.Name;

            ListView lstviewtemp1 = new ListView();
            ListView lstviewtemp2 = new ListView();
            lstviewtemp1 = (ListView)tabControl1.TabPages[SelectedTab].Controls[SelectedTab + "listview1"];
            lstviewtemp2 = (ListView)tabControl1.TabPages[SelectedTab].Controls[SelectedTab + "listview2"];

            listView1.Items.Clear();
            listView2.Items.Clear();

            foreach (ListViewItem item in lstviewtemp1.Items)
            {
                listView1.Items.Add(item.Text);
            }


            foreach (ListViewItem item in lstviewtemp2.Items)
            {
                listView2.Items.Add(item.Text);
            }

        }

     
    }
}
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100