Reputation: 53
I'm trying to compare the items in one list view with items in another list view with a button press. I want to transfer all items from one view to the other with this press. But only the items that are not all ready in the second list view.
What I've tried so far:
ElseIf Not ListView8.Items.Count = 0 Then
For Each item As ListViewItem In ListView8.Items
For Each item1 As ListViewItem In ListView7.Items
If Not item.Text.Equals(item1.Text) Then
ListView7.Items.Remove(item1)
ListView8.Items.Add(item1)
End If
Next
Next
End If
When I execute this code it matches the first items in each list view then only one item changes then they don't match and that item is inserted even if it's all ready in the 2nd view.
Upvotes: 1
Views: 567
Reputation:
You can do for example:
Dim newItems = From a In listView1.Items.OfType(Of ListViewItem)
Where (
Aggregate b In listView2.Items.OfType(Of ListViewItem)
Where b.Text.ToLower.Equals(a.Text.ToLower)
Into Count()
) = 0
Select a
newItems.ToList.ForEach(Sub(a)
listView2.Items.Add(DirectCast(a.Clone, ListViewItem))
listView1.Items.Remove(a)
End Sub)
Upvotes: 2