Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#. How do I fill ListView fully? All Items and all Subitems

everyone. How do I fill ListView fully at once. For example, I click some button and my LisView fills fully, all Items and all SubItems that I have.

like image 823
Frankie Drake Avatar asked Sep 08 '25 17:09

Frankie Drake


1 Answers

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});
like image 191
Justin Avatar answered Sep 10 '25 06:09

Justin