グリッド背景色を交互に表示する

gcMultiRow1のAlternatingRowsDefaultCellStyle プロパティ とRowsDefaultCellStyleで指定 これだけだと、新たな背景色のみ登録されるので、元の背景を変えたい場合は、 GcMultiRow.DefaultCellNoteStyle プロパティ でも色を指定する。 これで変更できない場合がある。そのときは以下のとおりにする。

DynamicCellStyle dynamicCellStyle1 = new DynamicCellStyle(); 

dynamicCellStyle1.ConditionHandler = new DynamicCellStyleConditionHandler(MyCondition); 

template1.Row.DefaultCellStyle = dynamicCellStyle1; gcMultiRow1.Template = template1; 

private CellStyle MyCondition(DynamicCellStyleContext context) { CellStyle cellStyle1 = new CellStyle(); 

// 1行おきにセルの背景色を変更する 
if (context.CellScope == CellScope.Row &&
 (context.RowIndex % 2) == 0) { cellStyle1.BackColor = Color.LightCyan; } else { cellStyle1.BackColor = Color.LightSalmon; } return cellStyle1; }

 

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です