有无做过INDEX类型的搜索

crmlihan 2003-09-13 01:11:32
今天真急,要交项目了,有个INDEX类型的搜索还不行。就是类似于金山词霸的那种,你输入ABC,那么以ABC为开头的单词都在列表种,且是动态变化的,有无高手给点意见?
...全文
24 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
goodname008 2003-09-19
  • 打赏
  • 举报
回复
知道它的ListIndex后,然后从第一个开始循环,把从第一个到这个ListIndex的条目全部放到某个数组里,同时在List中删除就可以了,恢复时再从数组里读出来。
crmlihan 2003-09-16
  • 打赏
  • 举报
回复
goodname008(卢培培,LPP Software) :
那怎么用把这个LISTITEM之前的自动隐藏起来呢?
jary12581 2003-09-13
  • 打赏
  • 举报
回复
另外一种方法,在窗体上添加一个listbox1和一个combox1控件,将搜索到的数据添加到combox1中。
private sub findtext(byval lhp as listbox)
dim i as integer
dim j as integer
dim m as integer
m=lhp.listcount
for i=0 to m-1
lhp.listindex=i
dim s as string
s=lhp.text
if instr(s,1,"abc")<>0 then
me.combox1.additem s
end if
next
end sub
jary12581 2003-09-13
  • 打赏
  • 举报
回复
你所说的就是类似于“搜索”,“搜索下一个”,下面给你一段代码,自己仔细研究去吧:
Private Sub serch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles serch.Click
yesornonext = False
findtext(1)
End Sub

'查找下一个
Private Sub serchnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles serchnext.Click
yesornonext = True
findtext(targetposition + 1)
End Sub

Private Sub findtext(ByVal startposition As Integer)
If yesornonext = False Then
findtextstr = Trim(InputBox("请输入要查找的文本:", "查找"))
End If
Dim activechild As Form = Me.ActiveMdiChild
If Not activechild Is Nothing Then
If Not activechild.ActiveControl Is Nothing Then
Dim therichtextbox As RichTextBox
therichtextbox = CType(activechild.ActiveControl, RichTextBox)
Dim pos As Integer
pos = InStr(startposition, therichtextbox.Text, findtextstr)
If pos > 0 Then
textnum = textnum + 1
targetposition = pos
therichtextbox.SelectionStart = targetposition - 1
therichtextbox.SelectionLength = Len(findtextstr)
Else
If yesornonext = False Then
MessageBox.Show("你要查找的文本不存在!", "提示", MessageBoxButtons.OK)
Else
MessageBox.Show("文本查找完毕!" & " " & "共" & CStr(textnum) & "处", "提示", MessageBoxButtons.OK)
End If
End If
End If
End If
End Sub
goodname008 2003-09-13
  • 打赏
  • 举报
回复
Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const LB_FINDSTRING = &H18F

Private Sub Form_Load()
List1.Clear
List1.AddItem "Apples"
List1.AddItem "Banana"
List1.AddItem "Bread"
List1.AddItem "Break"
Text1.Text = ""
End Sub

Private Sub Text1_Change()
List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
End Sub

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧