Reputation: 5961
I am trying to change the cell border colors based on the background color of the cell
this is what i have used
'Draw custom cell borders.
Using Brush As New SolidBrush(grdList.ColumnHeadersDefaultCellStyle.BackColor)
e.Graphics.FillRectangle(Brush, e.CellBounds)
End Using
e.Paint(e.CellBounds, DataGridViewPaintParts.All And Not DataGridViewPaintParts.ContentBackground)
Debug.Print(e.CellStyle.BackColor.ToString)
ControlPaint.DrawBorder(e.Graphics, e.CellBounds, e.CellStyle.BackColor, 1, _
ButtonBorderStyle.Solid, e.CellStyle.BackColor, 1, _
ButtonBorderStyle.Solid, e.CellStyle.BackColor, 1, _
ButtonBorderStyle.Solid, Color.Black, 1, _
ButtonBorderStyle.Solid)
this is the result
i dont what the white lines currently seen
Upvotes: 0
Views: 5353
Reputation: 125197
As an option you can set border styles yo none:
Me.DataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None
Then handle CellPainting
event and paint borders:
Private Sub DataGridView1_CellPainting(sender As Object, _
e As DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
If (e.ColumnIndex < 0 OrElse e.RowIndex < 0) Then Return
e.Paint(e.CellBounds, DataGridViewPaintParts.All)
Dim r = e.CellBounds
e.Graphics.DrawLine(Pens.Black, r.Left, r.Top, r.Right, r.Top)
e.Graphics.DrawLine(Pens.Black, r.Left, r.Bottom, r.Right, r.Bottom)
e.Handled = True
End Sub
Upvotes: 2