Back to Devexpress

DataGridView.CustomCellAppearance Event

maui-devexpress-dot-maui-dot-datagrid-dot-datagridview-d40c052e.md

latest4.4 KB
Original Source

DataGridView.CustomCellAppearance Event

Occurs before a data cell is painted.

Namespace : DevExpress.Maui.DataGrid

Assembly : DevExpress.Maui.DataGrid.dll

NuGet Package : DevExpress.Maui.DataGrid

Declaration

csharp
public event EventHandler<CustomCellAppearanceEventArgs> CustomCellAppearance

Event Data

The CustomCellAppearance event's data class is CustomCellAppearanceEventArgs. The following properties provide information specific to this event:

PropertyDescription
BackgroundColorGets or sets the cell background color.
ColumnGets the column that contains the cell.
FieldNameGets the field name of the column that contains the cell.
FontAttributesGets or sets whether the cell text is bold or italic.
FontColorGets or sets the cell text color.
FontFamilyGets or sets the font family name for the cell text.
FontSizeGets or sets the cell text size.
ItemGets an object that specifies the data source’s item to which the grid’s data row corresponds.
RowHandleGets the handle of the row that contains the cell.
TextDecorationsGets or sets whether the cell text is underlined and/or strike-through.

Remarks

Handle the CustomCellAppearance event to customize the appearance of each cell individually. Use the FieldName and RowHandle parameters to identify a column and row to which the cell belongs, BackgroundColor/FontColor to specify cell colors, and FontSize/FontFamily/FontAttributes to configure cell font settings.

Example

This example shows how to use the CustomCellAppearance event to customize the appearance of individual data cells within the grid.

  • Set different background colors for even and odd rows.
  • Change the font color for cells in the specified columns depending on their values.

xaml
<dxg:DataGridView x:Name="dataGridView" ItemsSource="{Binding}" 
                  CustomCellAppearance="DataGridView_CustomCellAppearance">
    <!-- ... -->
</dxg:DataGridView>
csharp
using Microsoft.Maui.Graphics;
using DevExpress.Maui.DataGrid;
// ...

void DataGridView_CustomCellAppearance(object sender, CustomCellAppearanceEventArgs e) {
    if (e.RowHandle % 2 == 0)
        e.BackgroundColor = Color.FromArgb("#F7F7F7");
    e.FontColor = Color.FromArgb("#55575C");
    if (e.FieldName == "ActualSales" || e.FieldName == "TargetSales") {
        double value = (double)dataGridView.GetCellValue(e.RowHandle, e.FieldName);
        if (value > 7000000)
            e.FontColor = Color.FromArgb("#00AE00");
        else if (value < 4000000)
            e.FontColor = Color.FromArgb("#FF5458");
    }
}

See Also

DataGridView Class

DataGridView Members

DevExpress.Maui.DataGrid Namespace