Newuser
Newuser

Reputation: 399

Listview is not populating all columns in a vertical manner

Background:

I have lists which store parsed data from sqlite columns. I want to show these lists in a listview to the user. They click a button and the list view should show these 3 lists and their contents.

The three lists are called, SeqIrregularities, MaxLen, and PercentPopList.

Problem: The listview is being populated in a horizontal manner (Shown below) which only contains contents of Seqirregularities list.The other 2 don't even show up. I want the listview to have contents of each list, vertically in the corresponding list column.

Side note: The listview is skipping the first column, another problem, but I can fix that.

enter image description here

Here's the code:

 ListViewItem lvi = new ListViewItem(); 
            foreach (object o in SeqIrregularities )
            {
                lvi.SubItems.Add(o.ToString());
            }
            foreach (object a in MaxLen )
            {
                lvi.SubItems.Add(a.ToString()); 
            }
            foreach (object b in PercentPopList)
            {
                lvi.SubItems.Add(b.ToString()); 
            }

            listView1.Items.Add(lvi);

Upvotes: 0

Views: 325

Answers (1)

Sudhakar Tillapudi
Sudhakar Tillapudi

Reputation: 26209

If you are adding items to ListViewItem object and assigning it to ListView it will create a single row because ListViewItem represents one row in ListView. from your code you are adding ListViewItem only one time, hence you will get only one Row that is Horizontally.

if you need to get the Multiple Rows (Vertically) you need to add the multiple ListViewItem objects to ListView .

        ListViewItem lvi = new ListViewItem(); 
        foreach (object o in SeqIrregularities )
        {
            lvi.SubItems.Add(o.ToString());
        }

        listView1.Items.Add(lvi);//Adds a new row
        lvi = new ListViewItem();

        foreach (object a in MaxLen )
        {
            lvi.SubItems.Add(a.ToString()); 
        }

        listView1.Items.Add(lvi);//Adds a new row
        lvi = new ListViewItem();

        foreach (object b in PercentPopList)
        {
            lvi.SubItems.Add(b.ToString()); 
        }

        listView1.Items.Add(lvi);//Adds a new row

Upvotes: 1

Related Questions