---restore content starts---
The ListView control is often used in WinForm development, if there are several ways to query the subitem subkey?
1. Use loop Traversal mode: (2.0)
<summary>///finds the index///</summary>///<param name= "View" > The ListView Control to find for a specific column in the ListView that contains the specified value </param>///<param name= "name" > specified column name</param>///<param name= "val" > Value to find </param>// /<returns> Find the value,-1 is not found </returns>public int getlistviewid (ListView view, string name, String val) {for (int i = 0; I < view. Items.Count; i++) {if (view. Items[i]. Subitems[name]. Text = = val) return i;} return-1;}
2. Using LINQ (3.5+)
LINQ queries can be used in the new version of the NET Framework, which simplifies the amount of code and improves readability.
ListViewItem li = listviewuser.items.cast<listviewitem> (). First (x = X.text = = "1005" && x.subitems["City"]. Text = = "Beijing"); string val = li. subitems["City"]. Text;
Other methods haven't been found yet, make a record, memo
---restore content ends---
How to search for a subkey in C # Lsitview