我建了command1、text1、list1,其中列表框中有很多内容,文本框中的内容和列表框中的一项内容是相同的。然后我想实现的功能是:我点按钮,列表框中删除和文本框内容相同的一项,哪位高手指点下,谢谢!

解决方案 »

  1.   

    还是直接上代码吧:Private Declare Function SendMessageByString& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)Private Sub Command1_Click()    Dim i&
        
        '查找文本,全字匹配(字母不区分大小写),找到则移除项目
        i = SendMessageByString(List1.hwnd, &H1A2, 0, Text1.Text)
        If (i >= 0) Then List1.RemoveItem i: exit sub
        MsgBox "没有找到该项目!", 64End Sub
      

  2.   

    纯 VB 方式
    Option ExplicitPrivate Sub Command1_Click()
        Dim s As String
        Dim i As Long
        
        s = Text1.Text
        For i = 0 To List1.ListCount - 1
            If List1.List(i) = s Then
                List1.RemoveItem i
                Exit For
            End If
        Next
    End Sub