Listbox is not adding Subitems

Asked

Viewed 92 times

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 only returning the following information: Coluna1 Coluna2 Coluna3

The Subitem data is missing! What am I doing wrong?

From now on, thank you!

1 answer

0


A few things are missing... In the Listitemview constructor goes the name of the Row, 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’ve helped.

  • Solved! Yeah, after I clicked on save I saw that I had typed Listbox, then the site didn’t let me edit, rsrs!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.