热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ListView控件的简单查询功能

例1:实现简单查找DimmyListAsNewListViewItemmyListListView1.FindItemWithText(‘查询字串’,True,0,T

例1:实现简单查找

Dim myList As New ListViewItem
myList = ListView1.FindItemWithText(‘查询字串’, True, 0, True)
ListView1.Focus()
If Not myList Is Nothing Then
ListView1.Items.Item(myList.Index).Selected = True
End If

例2:实现连续查询(这里要定义一个变量,用于保存查询起始的Index值)

Dim myList As New ListViewItem
Dim myIndex As Integer = 0 ‘myIndex的定义为全局变量
If myIndex > ListView1.Items.Count - 1 Then myIndex = 0
myList = ListView1.FindItemWithText(TextBox1.Text.Trim, True, myIndex, CheckBox1.Checked)
ListView1.Focus()
ListView1.MultiSelect = False
If Not myList Is Nothing Then
ListView1.TopItem = myList
ListView1.Items.Item(myList.Index).Selected = True
myIndex = myList.Index + 1
End If

在ListVeiw控件中实现查找、搜索功能,可以利用控件中的FindItemWithText函数来实现,下面先介绍下这个函数的定义

名称说明
FindItemWithText(String)查找以指定文本值开头的第一个 ListViewItem。 (继承自 ListView。)
FindItemWithText(String, Boolean, Int32)查找以指定文本值开头的第一个 ListViewItem 或 ListViewItem..::.ListViewSubItem(如果指定)。搜索从指定索引处开始。 (继承自 ListView。)
FindItemWithText(String, Boolean, Int32, Boolean)查找以指定文本值开头的第一个 ListViewItem 或 ListViewItem..::.ListViewSubItem(如果指定)。搜索从指定索引处开始。 (继承自 ListView。)

参数说明:

  • 第1个参数要搜索的文本。
  • 第2个参数 在搜索中包含子项时为 true;否则为false
  • 第3个参数 从该处开始执行搜索操作的项索引。
  • 第4个参数要将搜索文本与项的前缀相匹配,则为 true;否则为 false

注意:

  • 如果列表为空或者没有匹配项,FindItemWithText 方法将返回 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing)
  • 搜索不区分大小写。
  • text 参数可以指定所需匹配文本的一个子字符串。此方法将返回以指定文本开头的第一个项,除非为isPrefixSearch 传入了false。例如,如果 ListView 包含两个列表项,第一个项的文本设置为“angle bracket”,而第二个项的文本设置为“bracket”,那么,传递“brack”作为搜索文本来调用 FindItemWithText 将返回文本为“bracket”的项。如果isPrefixSearch 设置为false,此调用将返回nullNothingnullptrnull 引用(在 Visual Basic 中为Nothing)

其实函数中的第4个参数类似于“模糊查找”的选择,当选择True时为模糊查找方式(这里的模糊查找是有限制的,必须是项目头部的字串而不能选择中间或结束部分的字串进行查询操作),当选择False时则为准确查询方式。




推荐阅读
author-avatar
断雁难飞_920
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有