Devexpress gridcontrol change selected row color

user832747 picture user832747 · Feb 16, 2012 · Viewed 10.8k times · Source

I'm using FormatConditions to format certain rows based on their properties. E.g. I have a gridcontrol with many rows and some rows are colored red when there is an error. The issue I have is that when a row is selected, the formatting disappears and goes blue.

I would like the selected row color to be a slightly darker shade of whatever color that row is. I.e. You can still tell what color the row was shaded to be, but you can also tell that it's selected.

What's the best way to do this?

Answer

Niranjan Singh picture Niranjan Singh · Feb 21, 2012

Handle GridView.CustomDrawCell Event and Get the state of current Cell, whehter it belong to selected row or not.

//Get State of the cell - e.Cell provide access to current cell to paint-

 GridRowCellState state = ((GridCellInfo)e.Cell).State;

Then check for the selected row cell

if ((state & GridRowCellState.Selected) == GridRowCellState.Selected)
{
// do your custrom drawing here.
// for example 
e.DisplayText = "";
e.Appearance.BorderColor = Color.White;
}

Then set the CustomDrawEventArgs.Handled Property - e.Handled = true or false; after custom painting the cell as per your requirment.

Go Through these documentation links:
Custom Painting Basics
Custom Painting Samples