如何检测listbox和combobox里面重复的值?

    技术2022-05-11  61

    有时候需要检查待插入的值在listbox或者combobox里面有没有重复。可用两种方法:

    一、循环法'窗口中放入3个控件,list1,textbox1,command1测试OK!Private Sub Command1_Click()Addstr Text1.TextEnd SubSub Addstr(ByVal Str As String)        Dim i As Integer        For i = 0 To List1.ListCount - 1            If Str = List1.List(i) Then MsgBox "已经存在": Exit Sub        Next        List1.AddItem StrEnd Sub

    二、sendmessage法(比较快)n=SendMessage(List1.hwnd, LB_FindStringExact, -1, ByVal "重复")If  n>-1 Then  MsgBox "已存在!"End If

     


    最新回复(0)