Skip to main content

How to: Dynamically Customize Cell Appearance

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;
}