views:

45

answers:

1

Does anyone know how can I edit a subitem on a listView? I've tried using this:

ListView1.SelectedItems[0].SubItems[1].Text = "Hello?";

But that doesn't work. I get the error "InvalidArgument=Value of '1' is not valid for 'index'". I've got two columns on the listview, so I figured the index of [1] would be the subitem.

+2  A: 

Have you actually added an item with a subitem to the list? Just because you have two columns the ListViewItem doesn't automatically get 2 subitems.

For example if you have done the following:
ListViewItem item = listView1.Items.Add("test");
item.SubItems.Add("sub1");

Then it should work, but if you only have:
ListViewItem item = listView1.Items.Add("test");

Then it won't.

ho1
Ahh, thanks. It works now. I just assumed that it already had a value that could be edited. Thanks again.
Joey Morani