如果一个ListBox中有两个项是相同的,怎样删掉其中一个?

解决方案 »

  1.   

    试试
    Private Sub Command1_Click()
        Dim str1() As String
        Dim i As Integer
        Dim j As Integer
        Dim isY As Boolean
        
        For i = 0 To List1.ListCount - 1
            isY = False
            ReDim Preserve str1(i)
            For j = 0 To UBound(str1)
                If List1.List(i) = str1(j) And List1.List(i) <> "" Then
                    isY = True
                    Exit For
                End If
            Next
            If isY = False Then
                str1(i) = List1.List(i)
            Else
                List1.RemoveItem (i)
            End If
        Next
    End SubPrivate Sub Form_Load()
        List1.AddItem "a"
        List1.AddItem "b"
        List1.AddItem "a"
        List1.AddItem "c"
        List1.AddItem "a"
        List1.AddItem "d"
    End Sub
      

  2.   

    for i=0 to list1.listcount-1if list1.list(i)="123" then 
      list1.RemoveItem(i)
      exit for
    end ifnext