帮助如何从文本文件中搜索列表视图

帮助如何从文本文件中搜索列表视图

问题描述:

嗨!想知道在哪里可以找到搜索功能,以了解如何搜索保存在文本文件中的列表视图.

Hi! Would like to know where to find a search funcion for how to search to an listview that are saved in an text file.

如果要基于listview项,一种方法是遍历listviewitem及其子项.例如,以下内容选择了在项目或子项目中找到所需文本的所有项目.
If you want to do this based on the listview items, one way is to loop through the listviewitems and their subitems. For example the following selects all the items where desired text is found in the item or in the subitem.
foreach(ListViewItem item in mylistview.Items) {
   if (item.Text.Contains("text to search")) {
      item.Selected = true;
   }
   foreach (ListViewItem.ListViewSubItem subitem in item.SubItems) {
      if (item.Text.Contains("text to search")) {
         item.Selected = true;
      }
   }
}