简体   繁体   English

C#-如何通过键获取/设置ListViewItem或ListViewItem.ListViewSubItem?

[英]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: 我有一个带有动态创建的多个项目的listview,每个项目都有两个子项目,这些子项目是数量,对数据库的查询应该更新数量后的代码,但是为了使代码更具可读性,我想通过键而不是键来访问子项目根据其索引,类似:

subitem["quantity"] 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. 您必须设置ListViewItemListViewSubItemName属性才能使用该键。

From the ListViesSubItem documentation : ListViesSubItem 文档

The Name property corresponds to the key for a ListViewItem..::.ListViewSubItem in a ListViewItem..::.ListViewSubItemCollection. Name属性对应于ListViewItem .. ::。ListViewSubItemCollection中ListViewItem .. ::。ListViewSubItem的键。

The same is true for the ListViewItem. ListViewItem也是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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