1

I have a ListView that already has a populated first column.
I can easily use :

MylistView.Items.AddRange(new ListViewItem[] { item }) 

but since I already have the first column populated, I tried using:

MylistView.Items[0].SubItems.AddRange(new ListViewItem[] { item }) 

but I just get an error: enter image description here

I can always use the string[] overload, but is there a way to use the ListViewItem[] instead for the Subitems?

Here's my code:

ListViewItem item = new ListViewItem(new string[] { exp[listBox1.SelectedIndex].ToString(), exp2[listBox1.SelectedIndex].ToString() }); listView2.Items[0].SubItems.AddRange(new ListViewItem[] { item }); 
2
  • What error do you receive? Commented Apr 14, 2014 at 14:48
  • incorrect overload, i'll edit my post to put the error. Commented Apr 14, 2014 at 14:50

1 Answer 1

1

So why don't you just do:

listView2.Items[0].SubItems .AddRange(new [] { exp[listBox1.SelectedIndex].ToString(), exp2[listBox1.SelectedIndex].ToString(), }); 

The method expects either an array of strings or ListViewSubItems.

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

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.