按绑定数据设置单元格风格
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
gridView1.RowCellStyle += (s, e) => { var data = gridView1.GetRow(e.RowHandle); var card = data as I_Craft_Card; if (!card.DoMLackFlag.HasValue ) return; if (card.DoMLackFlag == 0) return; if (card != null) { if (e.Column.FieldName == "ter1" && (card.DoMLackFlag & 0x00000001) >0 ) { e.Appearance.BackColor = Color.Red; } if (e.Column.FieldName == "ter2" && (card.DoMLackFlag & 0x00000002) >0 ) { e.Appearance.BackColor = Color.Red; } if (e.Column.FieldName == "length" && (card.DoMLackFlag & 0x00000010) > 0) { e.Appearance.BackColor = Color.Red; } } };