When I make changes to a row, I change the background color of the cell. Therefore, I want to have a transparent row selector, so the user can see the changes.
I am getting very close. The following code does what I want, however, I have to manually select a different row for it to paint correctly.
So far my attempt to have this trigger automatically has not worked.
I attached (2) images. One is the initial load and the second is the desired results which I get if I click on another row. From that point on it works fine. With the exception that if I update another row, I have to manually change rows again for the updated background colors to show up again.
What an I doing wrong?
Private Sub dg_po_del_RowPostPaint(sender As System.Object, e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dg_po_del.RowPostPaint
If (dg_po_del.Rows(e.RowIndex).Selected) Then
Dim pen = New Pen(Color.Red)
Dim penWidth As Integer = 2
pen.Width = penWidth
Dim x As Integer = e.RowBounds.Left + (penWidth / 2)
Dim y As Integer = e.RowBounds.Top + (penWidth / 2)
Dim width As Integer = e.RowBounds.Width - penWidth
Dim height As Integer = e.RowBounds.Height - penWidth
e.Graphics.DrawRectangle(pen, x, y, width, height)
End If
Private Sub dg_po_del_RowEnter(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dg_po_del.RowEnter
If dg_po_del.RowCount <= 0 Then Exit Sub
Dim row As DataGridViewRow = dg_po_del.Rows(e.RowIndex)
row.DefaultCellStyle.SelectionBackColor = Color.Transparent
row.DefaultCellStyle.SelectionForeColor = Color.Black
End Sub
I am getting very close. The following code does what I want, however, I have to manually select a different row for it to paint correctly.
So far my attempt to have this trigger automatically has not worked.
I attached (2) images. One is the initial load and the second is the desired results which I get if I click on another row. From that point on it works fine. With the exception that if I update another row, I have to manually change rows again for the updated background colors to show up again.
What an I doing wrong?
Private Sub dg_po_del_RowPostPaint(sender As System.Object, e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dg_po_del.RowPostPaint
If (dg_po_del.Rows(e.RowIndex).Selected) Then
Dim pen = New Pen(Color.Red)
Dim penWidth As Integer = 2
pen.Width = penWidth
Dim x As Integer = e.RowBounds.Left + (penWidth / 2)
Dim y As Integer = e.RowBounds.Top + (penWidth / 2)
Dim width As Integer = e.RowBounds.Width - penWidth
Dim height As Integer = e.RowBounds.Height - penWidth
e.Graphics.DrawRectangle(pen, x, y, width, height)
End If
Private Sub dg_po_del_RowEnter(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dg_po_del.RowEnter
If dg_po_del.RowCount <= 0 Then Exit Sub
Dim row As DataGridViewRow = dg_po_del.Rows(e.RowIndex)
row.DefaultCellStyle.SelectionBackColor = Color.Transparent
row.DefaultCellStyle.SelectionForeColor = Color.Black
End Sub