0

I am trying to add items to a listView that has 2 columns. When I use the code below it will add an item to the first column and nothing to the second then it will create a new line with nothing in the first one and an item in the second, how do I get them both on the same line? Thanks.

listView1.Items.Add(item1); ListViewItem date = new ListViewItem(); date.SubItems.Add(subitem1); listView1.Items.Add(date); 

2 Answers 2

2

This works:

ListViewItem item = new ListViewItem("some item"); item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "sub item")); this.listView1.Items.Add(item); 

Set View property to the Details to check that everything right.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

That's because you are adding two ListViewItems to the ListView. Make it look similar to this:

 var item = new ListViewItem("first"); item.SubItems.Add("second"); item.SubItems.Add("third"); listView1.Items.Add(item); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.