troubleshooting Question

C# creating a tabpage with listview dynamically

Avatar of Jason
JasonFlag for Australia asked on
3 Comments1 Solution1041 ViewsLast Modified:
I need help with the code to create a dynamic tabpage with listview.

I can create the tabpage dynamically but I cant get the listview to be created.
The listview name will need to change when it is created.  I was trying to use the tab name to attach to the listview name for example tab name "Sample" the listview name "lvSample"

Any help would be great

private void tc1TabsAdd()
            foreach (ListViewItem i in listView2.Items)
                string x = i.Text;


        private void CreateMyListView(string x)
            Listview lv = "Listview" + x;
            // Create a new ListView control.
            ListView lv = new ListView();
            listView1.Bounds = new Rectangle(new Point(10, 10), new Size(300, 200));
            // Set the view to show details.
            listView1.View = View.Details;
            // Allow the user to edit item text.
            listView1.LabelEdit = true;
            // Allow the user to rearrange columns.
            listView1.AllowColumnReorder = true;
            // Display check boxes.
            listView1.CheckBoxes = true;
            // Select the item and subitems when selection is made.
            listView1.FullRowSelect = true;
            // Display grid lines.
            listView1.GridLines = true;
            // Sort the items in the list in ascending order.
            listView1.Sorting = SortOrder.Ascending;

            //Creat columns:
            ColumnHeader column1 = new ColumnHeader();
            column1.Text = "Customer ID";
            column1.Width = 159;
            column1.TextAlign = HorizontalAlignment.Left;

            ColumnHeader column2 = new ColumnHeader();
            column2.Text = "Customer name";
            column2.Width = 202;
            column2.TextAlign = HorizontalAlignment.Left;

            //Add columns to the ListView:

            // Add the ListView to the control collection.
Mike Tomlinson
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2009

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros