Skip to main content

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:GridControl.View>
    <dxg:TableView CustomRowAppearance="CustomRowAppearance" NavigationStyle="Row"> 
        <dxg:TableView.FormatConditions> 
            <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"/> 
        </dxg:TableView.FormatConditions> 
    </dxg:TableView>
</dxg:GridControl.View>

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