Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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