Avatar of Jason
Flag for Australia

asked on 

C# creating a tabpage with listview dynamically

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.

Open in new window


Avatar of undefined
Last Comment

8/22/2022 - Mon