ComboBox  如何控制相同数据重复加载

解决方案 »

  1.   

    晕,你大概是想限制重复加载吧?ComboBox  并没有find方法,大概只有循环判断来确定是不是重复了。
      

  2.   

    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
    Private Const CB_FINDSTRING = &H14C
    Private Sub Command1_Click()
    Dim index As Long
    Dim str As Stringstr = "abcD"  '判断这个项是否已经存在
    index = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal str)
    If index = -1 Then
        MsgBox "这个项还没有"
    Else
        MsgBox "这个项已经存在了"
    End If
    End Sub
      

  3.   

    如果是从数据库调用的话每次加载之前Combo1.Clear如果是单条加载的话
        Dim haveLoad As Boolean
        For i = 0 To Combo1.ListCount - 1 Step 1
            If Trim(Combo1.List(i)) = Trim(Text1.Text) Then
                haveLoad = True
                Exit For
            End If
        Next i
        If haveLoad = True Then
            Combo1.AddItem (Text1.Text)
        Else
            MsgBox "List中已存在此项"
        End If
      

  4.   

    赞成tztz520(午夜逛街)用API的做法。。顶
      

  5.   

    我只需要从数据库加载的时候,相同的项不加载进取    If Adodc7.Recordset.RecordCount <> 0 Then
        
          With Adodc7.Recordset
             .MoveFirst
             Do While Not .EOF
                cmb案卷类别.AddItem !卷类
                .MoveNext
             Loop
          End With
       End If