简体   繁体   中英

C# - How to get/set ListViewItem or ListViewItem.ListViewSubItem by key?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM