I have two combobox. I want to transfer all elements from combo1 to combo2 but with a filter only those item from combo1 will go to combo2 which are not in combo2.

For example

Combo1
________
This
Is
Help
But
Not

Combo2
_______
Is
But
And
Quick

So after clicking a button

Combo1
________
Is
But

Combo2
______
Is
But
And
Quick
This
Help
Not


Please help me......

Recommended Answers

All 6 Replies

Try this

Dim j As Integer = 0
        While j <= Me.ListBox1.Items.Count - 1


            Dim i As Integer = 0

            For i = 0 To Me.ListBox2.Items.Count - 1
                If Me.ListBox1.Items(j) = Me.ListBox2.Items.Item(i) Then
                    Exit For
                End If
            Next

            If i = Me.ListBox2.Items.Count Then
                Me.ListBox2.Items.Add(Me.ListBox1.Items.Item(j))
                Me.ListBox1.Items.RemoveAt(j)
            Else
                j += 1
            End If

        End While

What if i want to remove all items from combo1??

Just use ComboBox1.Items.Clear()

I see in your code that you use ListBox1 instead of ComboBox1

I replace that on my own and its working.. is that ok??

Oh sorry for that actually ListBox and ComboBox are like same...

Ok thank you @kingsonprisonic.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.