copyright 1999 - 2014 by heinz prelle - hannover  - lenbachstraße 42 - www.visual-basic5.de | impressum
'Beispiel: VB .Net - ComboBox - Doppelte Einträge entfernen
'
Option Explicit On
Option Strict On

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles Button1.Click
        Me.RemoveDublicateItems(Me.ComboBox1)
    End Sub

    Private Sub RemoveDublicateItems(ByVal cb As ComboBox)
        Dim j As Integer = 0
        Dim k As Integer = 0

        With cb
            For j = 0 To .Items.Count() - 2 Step 1
                For k = .Items.Count() - 1 To j + 1 Step -1
                    If .Items(j).ToString() = .Items(k).ToString() Then
                        .Items.RemoveAt(k)
                    End If
                Next
            Next
        End With
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles MyBase.Load
        Me.Text = "ComboBox - Remove dublicate items"
        Dim rnd As Random = New Random
        For n As Integer = 0 To 20
            Me.ComboBox1.Items.Add(CType(rnd.Next(0, 10), Integer))
        Next
    End Sub

End Class
Sourcecode Visual Basic