My DGV has row BackColors set to various colours based on business logic. When a user selects the row the colour changes to the selected row BackColor thus obscuring the pre-set colour. I would like to preserve the original colour when a row is selected and indicate selection with (perhaps) a bold border around the selected row. Is this possible? Is there an easy alternative I'm missing?
EDIT To make it clear, this is a WinForms app.
Another possibility is to set the selection color to be a darker shade of the normal back color. This would be much simpler than having to reimplement the drawing of borders of selected rows.
So when you add a row with, say, a yellow background
Dim backColor as Color = Color.Yellow
row.DefaultCellStyle.BackColor = backColor
row.DefaultCellStyle.SelectionBackColor = Color.FromArgb(backColor.R * 3 / 4, backColor.G * 3 / 4, backColor.B * 3 / 4)
Multiplying each color component by the same number < 1 serves to darken the color, you could play around with different values here to see what pleases you the most aesthetically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With