C#. How do I fill ListView fully? All Items and all Subitems
everyone. How do I fill List开发者_JAVA百科View fully at once. For example, I click some button and my LisView fills fully, all Items and all SubItems that I have.
I was also confused by this when I started using System.Windows.Forms.ListView
(I'm assuming that is the ListView
you're referring to).
Essentially, each row in the ListView corresponds to a single ListViewItem
in the .Items
collection. The text of the item appears in the first column of the ListView. When the ListView is in details mode (.View = View.Details
), then the SubItems
collection is used, which is a property of each ListViewItem
.
The pattern can be seen in the example code for ListView
on MSDN:
ListViewItem item1 = new ListViewItem("item1",0);
item1.SubItems.Add("1");
item1.SubItems.Add("2");
item1.SubItems.Add("3");
ListViewItem item2 = new ListViewItem("item2",1);
item2.SubItems.Add("4");
item2.SubItems.Add("5");
item2.SubItems.Add("6");
listView1.Items.AddRange(new ListViewItem[]{item1,item2});
I'm assuming you mean the .NET ListView?
You can change the View Property to 'Details' and that will show all items and subitems.
The SubItems get populated from second column onwards, if the listview has columns. The first column is taken by the top level item.
精彩评论