views:

552

answers:

2

I have a listview with several items that are created dynamically, each has two subitems that are quantity and code after a query to the database should update the quantity, but to make the code more readable I would like to access subitems by the key and not by its index, something like:

subitem["quantity"]

but I don't see how to assign the key though collections.

A: 

ListViewItem's subitems are not mainly accessible by using a string value like that in order to access it directly, it is integer based, such that SubItem[0] refers to the first sub-item, SubItem[1] refers to the second sub-item...and so on...

tommieb75
+1  A: 

You have to set the Name property of the ListViewItem or the ListViewSubItem to use the key.

From the ListViesSubItem documentation:

The Name property corresponds to the key for a ListViewItem..::.ListViewSubItem in a ListViewItem..::.ListViewSubItemCollection.

The same is true for the ListViewItem.

Obalix
Wow, many thanks for really fast answer, it had sought without success. Tested and OK.
Leonardo