Matt__W 发表于 2008-11-7 14:17:55

防止列表框中出现重复条目

有人有任何代码可以防止将重复条目添加到列表框中吗?VBA
**** Hidden Message *****

Matt__W 发表于 2008-11-7 14:55:10

刚碰到这个..
Public Function NoDuplicatesInList(lst As ListBox, str As String)
    Dim tf As Boolean
    Dim x As Integer
   
    If lst.ListCount = 0 And str"" Then
      lst.AddItem str
      'check to make sure no duplicate entries get into list box
    Else
      tf = False
      For x = 0 To lst.ListCount - 1
            If lst.List(x)str Then
                tf = False
            Else
                tf = True
                Exit For
            End If
      Next x
      If tf = False And str"" Then
            lst.AddItem str
      End If
    End If
End Function

Rogue 发表于 2008-11-10 13:21:56


如果是列表框,则只能由您通过代码添加项目。我会为列表框中的项目保存一个单独的字符串数组,并压缩数组中的项目——访问控件的属性会非常慢,尤其是当你有很多这样的控件时....
页: [1]
查看完整版本: 防止列表框中出现重复条目