title: How to merge cells in datagridview with equal values and draw line in a cell
body: <p>This is my dataGridview Result:</p>
  
  <p><a href="https://i.stack.imgur.com/Ibwwx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ibwwx.jpg" alt=""></a></p>
  
  <p>and what I expect:</p>
  
  <p><a href="https://i.stack.imgur.com/BF9n2.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BF9n2.jpg" alt=""></a></p>
  
  <p>I want to merge cells in first column that are equal. I'm using this code:</p>
  
  <pre><code>    Private Sub DataGridView2_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles DataGridView2.CellPainting
  
      If e.RowIndex = 0 Then
  
          If (DataGridView2.Rows(e.RowIndex).Cells(0).Value.ToString() = DataGridView2.Rows(e.RowIndex + 1).Cells(0).Value.ToString()) Then
              If (e.ColumnIndex = 0) Then
                  DataGridView2.Rows(e.RowIndex + 1).Cells(0).Value = ""
                  e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None
              End If
          End If
  
      End If
  
      If e.RowIndex &gt; 0 Then
          If e.RowIndex &lt; DataGridView2.Rows.Count - 2 Then
              If (DataGridView2.Rows(e.RowIndex - 1).Cells(0).Value.ToString() = DataGridView2.Rows(e.RowIndex).Cells(0).Value.ToString()) Then
                  If (e.ColumnIndex = 0) Then
                      DataGridView2.Rows(e.RowIndex).Cells(0).Value = ""
                      e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None
                  End If
              End If
  
              If (DataGridView2.Rows(e.RowIndex).Cells(0).Value.ToString() = DataGridView2.Rows(e.RowIndex + 1).Cells(0).Value.ToString()) Then
                  If (e.ColumnIndex = 0) Then
                      DataGridView2.Rows(e.RowIndex + 1).Cells(0).Value = ""
                      e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None
                  End If
              End If
          End If
  
      End If
  End Sub
  </code></pre>
  
  <p>It works but when I select a row, becomes corrupted. Also I would like to separate my data for each group by a red line. In addition draw a diagonal in top cell and write the names.</p>