Click here to Skip to main content
15,889,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i have two data grid views and in the first data grid view i have 3 column

ID SUBJECT RECEIVED

and second data grid view 8 columns

ID subject received date user etc

i want to check the subject line in the first data grid view with second data grid view's subject and say "matching" or " not matching in the "mark" column in second data grid view.

someone please help me with this double loop

What I have tried:

VB.NET
'Dim rowindex As String
        'Dim found As Boolean = False
        '' 
        'Dim i As Integer = 1

        'For Each row As DataGridViewRow In LiveinboxDataGridView.Rows
        '    For Each rowww As DataGridViewRow In ElapsedDataGridView.Rows
        '        Dim str As String
        '        str = TextBox1.Text
        '        Dim xxx As String = rowww.Cells.Item(10).Value

        '        MsgBox(xxx)
        '        MsgBox(row.Cells.Item(7).Value)
        '        If row.Cells.Item(7).Value = xxx Then
        '            ' rowindex = row.Index.ToString()
        '            found = True
        '            '  Dim actie As String = rowww.Cells("Received").Value.ToString()
        '            MsgBox("Found")
        '            '   Exit For
        '            'Exit For
        '        End If

        '    Next
        'Next
        'If Not found Then
        '    MsgBox("Item not found")
        'End If
Posted
Updated 12-Nov-16 23:12pm
Comments
[no name] 13-Nov-16 12:06pm    
You would have to uncomment your code before it would actually do anything.

1 solution

Start by simplifying that: Create a List Of String and populate it with the Subject values from the first DataGridView - that's a trivial For Each loop.
When you have that, you can use the Linq Contains method to check if the list contains each value: Enumerable.Contains(TSource) Method (IEnumerable(TSource), TSource) (System.Linq)[^] - it returns a Boolean which you can use to set the value of your Mark column directly.
That way, you don't need to nest the loops, and you process N1 + N2 loops, instead of N1 * N2
 
Share this answer
 
Comments
Member 12430081 13-Nov-16 13:11pm    
Hi really appreciate your idea.. i never did it before.. can you post some link to any example..
OriginalGriff 13-Nov-16 13:32pm    
You know how to do a for each loop on the rows, it's in your code.
And you can access the cell from the row - again in your code.
And you should know how to add an item to a list.
So which bit is giving you problems?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900