提供一下三种方法
1.使用设计器
点击gridcontrol控件,run designer,format Condtions, add,然后进行各种条件的设置。
2.用代码代替设计器。
实例代码:
private void SetWarning()
{
#region 应收预警 应收100万以内绿色;100-300万蓝色;300-500万黄色;500-700万橙色;700万以上红色。
StyleFormatCondition condition = new StyleFormatCondition();
condition.Appearance.Options.UseForeColor = true;
condition.Appearance.ForeColor = Color.Green;
condition.Column = bandedGridViewSalesDailyReport.Columns["Diff"];
condition.Condition = DevExpress.XtraGrid.FormatConditionEnum.Expression;
condition.Expression = "1000000>Abs([Diff])";
condition.Value1 = true; StyleFormatCondition condition2 = new StyleFormatCondition();
condition2.Appearance.Options.UseForeColor = true;
condition2.Appearance.ForeColor = Color.Yellow;
condition2.Column = bandedGridViewSalesDailyReport.Columns["Diff"];
condition2.Condition = DevExpress.XtraGrid.FormatConditionEnum.Expression;
condition2.Expression = "3000000 > Abs([Diff]) And Abs([Diff]) > 3000000";
condition2.Value1 = true; StyleFormatCondition condition4 = new StyleFormatCondition();
condition4.Appearance.Options.UseForeColor = true;
condition4.Appearance.ForeColor = Color.Orange;
condition4.Column = bandedGridViewSalesDailyReport.Columns["Diff"];
condition4.Condition = DevExpress.XtraGrid.FormatConditionEnum.Expression;
condition4.Expression = "7000000 > Abs([Diff]) And Abs([Diff]) > 5000000"; condition4.Value1 = true; StyleFormatCondition condition6 = new StyleFormatCondition();
condition6.Appearance.Options.UseForeColor = true;
condition6.Appearance.ForeColor = Color.Red;
condition6.Column = bandedGridViewSalesDailyReport.Columns["Diff"];
condition6.Condition = DevExpress.XtraGrid.FormatConditionEnum.Expression;
condition6.Expression = "Abs([Diff])>7000000";
condition6.Value1 = true;
this.bandedGridViewSalesDailyReport.FormatConditions.AddRange(new DevExpress.XtraGrid.StyleFormatCondition[] {
condition,
condition2,
condition4,
condition6
});
#endregion 应收预警
}
3.在绘制行或者单元格时候设置
示例代码1:
private void bandedGridViewSalesDailyReport_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
Color c = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)())))); if (e.Column.FieldName == "Diff")
{
e.Column.AppearanceCell.BackColor = c;
} if (e.Column == this.colPrepayment)
{
e.Column.AppearanceCell.BackColor = c;
}
if (e.Column == colTotalAmount)
{
e.Column.AppearanceCell.BackColor = c;
}
}
示例代码2:
private void gridViewShipment_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (e.Column == this.colSettlementStatus && e.CellValue != null)
{
if (e.CellValue.ToString() == "完成结算")
{
e.Appearance.ForeColor = Color.Green;
}
else
if (e.CellValue.ToString() == "未结算")
{
e.Appearance.ForeColor = Color.Red;
}
else
{
e.Appearance.ForeColor = Color.Orange;
}
}
}