加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

在listBox中搜索指定的字符串VB6

发布时间:2020-12-17 00:08:07 所属栏目:大数据 来源:网络整理
导读:我有一个名为lstSerial的列表框和一个名为txtSerials的文本框.我想要做的是搜索lstSerial以获取在txtSerials中输入的字符串.我在Microsoft Visual Basic 6.0中使用VB6,而且我很难找到文档. 谢谢. @ AlexK的回答在技术上是正确的 – 是的 – 它会起作用,但它
我有一个名为lstSerial的列表框和一个名为txtSerials的文本框.我想要做的是搜索lstSerial以获取在txtSerials中输入的字符串.我在Microsoft Visual Basic 6.0中使用VB6,而且我很难找到文档.

谢谢.

@ AlexK的回答在技术上是正确的 – 是的 – 它会起作用,但它不是首选的方式.为此目的有一个API调用:
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" _
     (ByVal hWnd As Long,ByVal wMsg As Long,ByVal wParam As _
     Integer,ByVal lParam As Any) As Long

'constants for searching the ListBox
Private Const LB_FINDSTRINGEXACT = &H1A2
Private Const LB_FINDSTRING = &H18F

'function to get find an item in the Listbox
Public Function GetListBoxIndex(hWnd As Long,SearchKey As String,Optional FindExactMatch As Boolean = True) As Long

    If FindExactMatch Then
        GetListBoxIndex = SendMessage(hWnd,LB_FINDSTRINGEXACT,-1,ByVal SearchKey)
    Else
        GetListBoxIndex = SendMessage(hWnd,LB_FINDSTRING,ByVal SearchKey)
    End If

End Function

所以你想这样做:

lstSerial.ListIndex = GetListBoxIndex(lstSerial.hWnd,txtSerials.Text)

Source

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读