ListBox is not adding SubItems

0

I used the following code:

ListViewItem item1 = new ListViewItem("Coluna1");
item1.SubItems.Add("SubItem1a");
item1.SubItems.Add("SubItem1b");
item1.SubItems.Add("SubItem1c");

ListViewItem item2 = new ListViewItem("Coluna2");
item2.SubItems.Add("SubItem2a");
item2.SubItems.Add("SubItem2b");
item2.SubItems.Add("SubItem2c");

ListViewItem item3 = new ListViewItem("Coluna3");
item3.SubItems.Add("SubItem3a");
item3.SubItems.Add("SubItem3b");
item3.SubItems.Add("SubItem3c");

listView1.Items.AddRange(new ListViewItem[] {item1,item2,item3});

However, my listView1 is returning only the following information: Column1 Column2 Column3

SubItem data does not appear! What am I doing wrong?

Thanks in advance!

    
asked by anonymous 06.07.2016 / 05:28

1 answer

0

Some more things are missing ... In the ListItemView constructor the name of the row is placed, the columns are placed separately, and have to activate to show the subitems (View.Details).

Try to run this code:

 listView1.View = View.Details;

 ListViewItem item1 = new ListViewItem("Linha1");
 item1.SubItems.Add("SubItem1a");
 item1.SubItems.Add("SubItem1b");
 item1.SubItems.Add("SubItem1c");

 ListViewItem item2 = new ListViewItem("Linha2");
 item2.SubItems.Add("SubItem2a");
 item2.SubItems.Add("SubItem2b");
 item2.SubItems.Add("SubItem2c");

 ListViewItem item3 = new ListViewItem("Linha3");
 item3.SubItems.Add("SubItem3a");
 item3.SubItems.Add("SubItem3b");
 item3.SubItems.Add("SubItem3c");

 listView1.Columns.Add("Coluna 1");
 listView1.Columns.Add("Coluna 2");
 listView1.Columns.Add("Coluna 3");
 listView1.Columns.Add("Coluna 4");

 listView1.Items.AddRange(new ListViewItem[] { item1, item2, item3 });

Ah, and it's a ListView, not ListBox!

I hope I have helped.

    
07.07.2016 / 00:27