Skip to main content
A newer version of this page is available. .

GridView.RowCellStyle Event

Enables the appearance settings of individual cells to be changed.

Namespace: DevExpress.XtraGrid.Views.Grid

Assembly: DevExpress.XtraGrid.v17.2.dll

Declaration

[DXCategory("Appearance")]
public event RowCellStyleEventHandler RowCellStyle

Event Data

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

Property Description
Appearance Gets the appearance settings used to paint the data cell currently being processed.
CellValue Returns the currently processed cell value. Inherited from CustomRowCellEventArgs.
Column Gets the column to which the currently processed cell corresponds. Inherited from CustomRowCellEventArgs.
RowHandle Gets the handle of the row that contains the processed cell. Inherited from CustomRowCellEventArgs.

The event data class exposes the following methods:

Method Description
CombineAppearance(AppearanceObject) Copies the activated settings of the appearance object passed as the parameter.

Remarks

The RowCellStyle event is raised for individual cells before they need to be repainted. The referenced cell can be identified using the event’s CustomRowCellEventArgs.RowHandle and CustomRowCellEventArgs.Column parameters. To customize the cell’s appearance settings, use the RowCellStyleEventArgs.Appearance property.

To provide appearance settings for entire rows (not just for individual cells) the GridView.RowStyle event can be handled instead.

Setting an image to the Appearance.Image property has no effect when custom painting via the RowCellStyle and GridView.RowStyle events.

Note

The control’s events designed to change the appearance or rendering of control elements must not be used to update cell values or to modify the control’s layout. Any inappropriate operation which causes a layout update, may break the normal control behavior.

Please refer to the Appearance and Conditional Formatting topic for additional information.

Online Video

WinForms Grid: Custom Drawing.

Example

The following code demonstrates how to customize the appearance of individual grid cells using the GridView.RowCellStyle event handler. The grid cells in this example are colored in a staggered manner. The following image demonstrates the result:

Examples.RowCellStyle

using DevExpress.XtraGrid.Views.Grid;

private void gridView1_RowCellStyle(object sender, RowCellStyleEventArgs e) {
   GridView view = sender as GridView;
   if(view == null) return;
   if(e.RowHandle != view.FocusedRowHandle && 
      ((e.RowHandle % 2 == 0 && e.Column.VisibleIndex % 2 == 1) || 
      (e.Column.VisibleIndex % 2 == 0 && e.RowHandle % 2 == 1)))    
      e.Appearance.BackColor = Color.NavajoWhite;
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the RowCellStyle event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also