Listview Details view not displaying anything
Asked Answered
F

2

15

I'm trying to use a details view mode of a ListView in winforms, but none of the items are displaying. The listview itself is growing as items are added, but nothing is being displayed.

It is displaying the items in list mode, but just not in Details mode.

I have used the following code, any ideas?

forms_listView.Columns.Add("URL");
forms_listView.Columns.Add("Position");

and

ListViewItem lvi = new ListViewItem();
lvi.Tag = form;
lvi.Text = form.URL;
lvi.Name = "URL";
ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem(lvi, "Position");
subItem.Name = "Position";
subItem.Text = ""+form.Position;
lvi.SubItems.Add(subItem);
forms_listView.Items.Add(lvi);
Faint answered 27/3, 2011 at 18:49 Comment(2)
Your problem is not in that bit of code.Silent
@David Heffernan Thanks. Due to your comment, I looked around elsewhere and found it :) Never realized that clear removes columns as wellFaint
F
29

I found my problem. I was calling the listview.Clear() method which in the documentation says that it removes all items and all columns, which was causing no items to be displayed.

Faint answered 27/3, 2011 at 19:11 Comment(3)
lol I've been trying to debug the same problem for past 20 mins! thanks :) need to call listview.Items.Clear()Voltaire
Answer was useful to C++ too, as I needed to call ListView_SetExtendedListViewStyle and ListView_InsertColumn first (the other views looked fine).Beauteous
It's always the dumbest little thing, isn't it?Plebe
R
4
forms_listView.Columns.Add("First Column Title"); 
... 
forms_listView.Columns.Add("Last Column Title");  
Reichert answered 28/3, 2011 at 3:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.