title: Counting duplicates in datagridview and displaying number of duplicates
body: <p>Hi I am trying to count the number of duplicates in my unbound datagrid.</p>
  
  <p>My problem is that when I clear my string it then starts the count a fresh count and dismisses the previous duplicate entries but if I do not clear the string I get the number of duplicates as the 2nd digit in my string this is fine but I need it do search for duplicates and display the number or duplicates of that sort in the column</p>
  
  <p>I press the button.</p>
  
  <pre><code>Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
          DataGridView2.ColumnCount = 7
  
          DataGridView2.Columns(0).Name = ""
          DataGridView2.Columns(1).Name = ""
          DataGridView2.Columns(2).Name = ""
          DataGridView2.Columns(3).Name = ""
          DataGridView2.Columns(4).Name = ""
          DataGridView2.Columns(5).Name = ""
          DataGridView2.Columns(6).Name = "UID"
  
          Dim row As String() = New String() {"", "", "", "", "", "", "" &amp; Label1.Text &amp; "" &amp; Label4.Text &amp; " " &amp; Label3.Text &amp; " " &amp; Label5.Text &amp; " " &amp; Label6.Text &amp; ""}
          DataGridView2.Rows.Add(row)
  
  Timer7.Start()
  
  End Sub
  </code></pre>
  
  <p>Then This</p>
  
  <pre><code>Private Sub Timer7_Tick(sender As Object, e As EventArgs) Handles Timer7.Tick
    Dim date1 As String = DateTime.Now.ToString("dd MMMM yyyy")
      Form3.DataGridView1.ColumnCount = 7
      Form3.DataGridView1.Columns(0).Name = "SERIAL"
      Form3.DataGridView1.Columns(1).Name = "PORT"
      Form3.DataGridView1.Columns(2).Name = "Attempt"
      Form3.DataGridView1.Columns(3).Name = "PEAK IM3"
      Form3.DataGridView1.Columns(4).Name = "Date of Data"
      Form3.DataGridView1.Columns(5).Name = "Time of Data"
      Form3.DataGridView1.Columns(6).Name = "UID"
      Dim row As String() = New String() {"" &amp; Label1.Text &amp; "", "" &amp; Label4.Text &amp; " " &amp; Label3.Text &amp; " " &amp; Label5.Text &amp; " " &amp; Label6.Text &amp; "", "" &amp; Label15.Text &amp; "", "", date1, CStr(TimeOfDay), "" &amp; Label1.Text &amp; "" &amp; Label4.Text &amp; " " &amp; Label3.Text &amp; " " &amp; Label5.Text &amp; " " &amp; Label6.Text &amp; ""}
      Form3.DataGridView1.Rows.Add(row)
  
      Dim dc As New Dictionary(Of String, Integer)()
      Dim clV As String
  
      For i As Integer = 0 To Form3.DataGridView1.Rows.Count - 1
  
          If Not Form3.DataGridView1.Rows(i).IsNewRow Then
  
              clV = Me.DataGridView2(6, i).Value.ToString()
  
              If Not dc.ContainsKey(clV) Then
                  dc.Add(clV, +1)
              Else
                  dc(clV) += 1
              End If
          End If
      Next
  
      Dim sb As New StringBuilder()
  
      For Each kvp As KeyValuePair(Of String, Integer) In dc
          sb.AppendLine(String.Format("{0} ", kvp.Value))
      Next
  
      Label15.Text = sb.ToString()
  
      Timer7.Stop()
  End Sub
  </code></pre>
  
  <p>I have spent 2 days trying to figure this out and need some advice on what to do.</p>