Results 1 to 10 of 10

Thread: How do I compare the items of two listboxes?

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2017
    Posts
    33

    How do I compare the items of two listboxes?

    I have two listboxes (1: Primary, 2:Secondary). These listboxes contain numbers. The Primary Listbox contains 7 numbers, and the Secondary Listbox contains 6 numbers.

    Name:  Capture#1.JPG
Views: 2380
Size:  15.4 KB

    I want to compare the values of the Primary Listbox to those of the Secondary. This comparison should yield three results:

    Result #1: X number of values were found to be common.

    Name:  Result#1.JPG
Views: 2229
Size:  12.0 KB

    Result#2: All numbers matched.

    Name:  Result#2.JPG
Views: 2207
Size:  10.7 KB

    Result#3: No matches found.

    Name:  Result#3.JPG
Views: 2175
Size:  11.6 KB

    This is what I have so far:

    Code:
    If lstPrimaryNumbers.Items.Count = 0 Or lstSecondaryNumbers.Items.Count = 0 Then
                MessageBox.Show("There is nothing to compare.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
    
    
            Dim r = lstPrimaryNumbers.Items.Cast(Of String).Where(Function(x) lstSecondaryNumbers.Items.Contains(x))
            MessageBox.Show(String.Join(",", r) & " matched")
    Note: I`m only dealing with integer values in the two listboxes.
    Last edited by Me.User; Jul 13th, 2018 at 10:54 AM. Reason: Added attachment

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width