从filelistbox中选中多个项目然后向listbow添加项目时,怎样确保不出现重复.

解决方案 »

  1.   

    添加到 ListBox 中,首先判断是否存在于 Listbox 中。
      

  2.   

    怎样才用判断是否有多个项目存在listbox中.
      

  3.   

    Private Sub Command1_Click()
      Dim i As Long, j As Long
      Dim bDuplicate As Boolean
      
      For i = 0 To File1.ListCount - 1
        If File1.Selected(i) Then
          If List1.ListCount > 0 Then
            bDuplicate = False
            For j = 0 To List1.ListCount - 1
              If List1.List(j) = File1.List(i) Then
                bDuplicate = True
                Exit For
              End If
            Next
            If Not bDuplicate Then List1.AddItem File1.List(i)
          Else
            List1.AddItem File1.List(i)
          End If
        End If
      Next
    End Sub