A newer version of this page is available. Switch to the current version.

Formatting Focused Cells and Rows

  • 2 minutes to read

By default, when a user focuses a cell or row, the standard background color overrides the color specified by conditional formatting.

CustomRowAppearance TableView

The GridControl allows you to customize the color of a focused cell or row that has conditional formatting applied. You can either provide a specific value or choose a color based on a custom logic using the CustomRowAppearance event. Depending on the grid’s view type, you can either use the TableView.CustomRowAppearance or TreeListView.CustomRowAppearance events.

In the following code sample, the row background color is modified by the ShadeBrush() method. The color is calculated based on the value defined by conditional formatting.

    <dxg:TableView CustomRowAppearance="CustomRowAppearance" NavigationStyle="Row"> 
            <dxg:DataBarFormatCondition FieldName="Profit" PredefinedFormatName="GreenGradientDataBar" /> 
            <dxg:FormatCondition FieldName="Profit" Expression="[Profit]&lt;0" PredefinedFormatName="RedText"/> 
            <dxg:FormatCondition FieldName="Profit" Expression="[Profit]&gt;=0" PredefinedFormatName="GreenText"/> 
            <dxg:FormatCondition FieldName="Profit" Expression="[Profit]&lt;=0" PredefinedFormatName="LightRedFillWithDarkRedText" ApplyToRow="True"/> 

The image below illustrates the result.

CustomRowAppearance TableView2

To control the background color of individual focused cells that have conditional formatting applied, handle the TableView.CustomCellAppearance or TreeListView.CustomCellAppearance events in a similar way.

See Also