Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
If e.ColumnIndex <> -1 AndAlso e.RowIndex <> -1 Then
Dim current As DataGridViewCell = DataGridView1.Item(e.ColumnIndex, e.RowIndex)
If current.Selected Then
e.Paint(e.CellBounds, e.PaintParts)
Using p As New Pen(Color.Red, 1)
Dim rct As Rectangle = e.CellBounds
rct.Offset(-1, -1)
rct.Inflate(-1, -1)
e.Graphics.DrawRectangle(p, rct)
End Using
e.Handled = True
End If
End If
End Sub