title: Get Distinct rows from datagridview1 and pass into datagridview2
body: <p>I got this code where it select distinct values from datagridview1 and pass the result to datagridview2:</p>
  
  <p>Further Details:
  Data from datagridview1</p>
  
  <pre><code>Code   Amount
  Pro1   100.00
  Pro2   300.00
  Pro1   100.00
  Pro1   100.00
  Pro2   300.00
  </code></pre>
  
  <p>The result should be placed in datagridview2 like below;</p>
  
  <pre><code>Code   Amount   Count
  Pro1   100.00     3
  Pro2   300.00     2
  </code></pre>
  
  <p>CODE:</p>
  
  <pre><code>Dim dic As New Dictionary(Of String, Integer)()
          Dim cellValue As String = Nothing
          For i As Integer = 0 To dgvSubjectsEnrolled.Rows.Count - 1
              If Not dgvSubjectsEnrolled.Rows(i).IsNewRow Then
                  If dgvSubjectsEnrolled(0, i).Value &gt; 0 Then
                      cellValue = dgvSubjectsEnrolled(0, i).Value.ToString()
                      If Not dic.ContainsKey(cellValue) Then
                          dic.Add(cellValue, 1)
                      Else
                          dic(cellValue) += 1
                      End If
                  Else
                  End If
  
              End If
          Next
  
          Dim sb1 As New StringBuilder()
          Dim sb2 As New StringBuilder()
          For Each keyvalue As KeyValuePair(Of String, Integer) In dic
              sb1.AppendLine(String.Format("{0}", keyvalue.Key, keyvalue.Value))
              sb2.AppendLine(String.Format("{1}", keyvalue.Key, keyvalue.Value))
          Next
          Me.dgvsub.Rows.Add(sb1.ToString, sb2.ToString())
  </code></pre>
  
  <p>The code executed successfully but the result is:</p>
  
  <pre><code>  Code         Count
  Pro1Pro2        32
  </code></pre>
  
  <p>The data was concatenated with the same row. The next value should be at the next row.
  Please edit this code.</p>