Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add the items to start from the second cell and not in the column header cell?

private void DisplayTableWithListview()
        {
            listView1.GridLines = true;// Whether the grid lines are displayed
            listView1.FullRowSelect = true;// Whether to select the entire line

            listView1.View = View.Details;// Set display mode
            listView1.Scrollable = true;// Whether to show the scroll bar automatically
            listView1.MultiSelect = false;// Is it possible to select multiple lines

            // Add header(column)
            listView1.Columns.Add("ToString(yyyyMMddHHmm)", 160, HorizontalAlignment.Center);
            
            // Add items into table
            for (int i = 0; i < 6; i++)
            {
                ListViewItem item = new ListViewItem();
                item.SubItems.Clear();

                item.SubItems[0].Text = "Product" + i.ToString();
                item.SubItems.Add(i.ToString());
                item.SubItems.Add((i + 7).ToString());
                item.SubItems.Add((i * i).ToString());
                listView1.Items.Add(item);
            }
        }

Product0 is in the cell/place of the column header.
i want the items to be start added from the second cell.

table

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you can use listView1.Items.Insert(index , item) to add item in specialty index. listview.listviewitemcollection.insert()

listView1.Items.Insert(2,"yourItem");

if you want the items to be start added from the second cell try this:

        listView1.Items.Add("");
        for (int i = 0; i < 6; i++)
        {
            ListViewItem item = new ListViewItem();
            item.SubItems.Clear();

            item.SubItems[0].Text = "Product" + i.ToString();
            item.SubItems.Add(i.ToString());
            item.SubItems.Add((i + 7).ToString());
            item.SubItems.Add((i * i).ToString());
            listView1.Items.Add(item);
        }

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading