Edit a listview subitem

Hi,

I have a listview with 3 columns, and some rows.
I have searched the internet for a code to edit a value of a subitem.
I found soms code, like: ListView1.ListItems(2).SubItems(3) = "something", but this won't work.
Does someone can help me?

(Sorry for my limited English)

Greetings,
Robin

[490 byte] By [robinva] at [2008-2-14]
# 1
Hi Robin,

Try this and I haven't compiled it...

Dim lvi as listviewitem = listview.items(i)

Edit the item and then use the replace method to replace the unedited item with the new one.

ReneeC at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2

Robin,
Are you using VB6 and the Listview control from that? If memory serves me correctly, the listitems and subitems are 0 based collections. So if you have 3 columns, they should be indexed 0-2.

VB6:
Debug.Print ListView1.ListItems(0).SubItem(0).Text
Debug.Print ListView1.ListItems(0).SubItem(2).Text

If you are using Visual Basic 2005, then you need to change your code since the new control has an Items collection, not a ListItems collection. Here is code for .Net.

VB2005:
Debug.Print(ListView1.Items(0).SubItems(0).Text)
ListView1.Items(0).SubItems(0).Text =
"foo"

Adam Braden
Visual Basic Team

AdamBraden-MS at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...