Draw a bracket between two or more rows in DataGridView

  • Thread starter Thread starter George Waters
  • Start date Start date
G

George Waters

Guest
Hi,

I am trying to draw some brackets between rows to show the user that two or more rows belong to a group based on a hidden column value, when it loads looks ok, but as soon as I scroll down, the mess starts.

1447497.png 1447499.png

Private Sub dgcontrol_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs) Handles dgcontrol.CellPainting

If sender.Columns(e.ColumnIndex).Name = "xrow2" Then
Dim rec1 As Rectangle = dgcontrol.GetCellDisplayRectangle(2, 0, False)
Dim rec2 As Rectangle = dgcontrol.GetCellDisplayRectangle(2, 1, False)
Dim gridBrush As Brush = New SolidBrush(Color.Red)
Dim gridLinePen As Pen = New Pen(gridBrush, 2)
e.Graphics.DrawLine(gridLinePen, New Point(rec1.X + rec1.Width - 2 - rec1.Width / 5, rec1.Y + rec1.Height / 3), New Point(rec1.X + rec1.Width - 2, rec1.Y + rec1.Height / 3))
e.Graphics.DrawLine(gridLinePen, New Point(rec2.X + rec1.Width - 2 - rec1.Width / 5, rec2.Y + rec2.Height - rec2.Height / 3), New Point(rec2.X + rec1.Width - 2, rec2.Y + rec2.Height - rec2.Height / 3))
e.Graphics.DrawLine(gridLinePen, New Point(rec1.X + rec1.Width - 3, rec1.Y + rec1.Height / 3), New Point(rec2.X + rec1.Width - 3, rec2.Y + rec2.Height - rec2.Height / 3))
e.Handled = False
End If

End Sub



Thanks in advance.


G.Waters

Continue reading...
 
Back
Top