使用GridFormatRule 可以轻松设置GridControl中的格式化规则,这些规则的使用可以方便的控制显示,区别不同的数据格式。参见链接:
FormatConditionRuleExpression Expression Operators, Functions, and Constants 下面 在 gcId 列(上一篇文章定义)应用了Rule的效果。
应用到单元格:
应用到整行:
设置代码:
gcId.Caption = "编号";
gcId.FieldName = "Id";
gcId.VisibleIndex = 0;
gcId.Width = 15;
this.gv.Columns.Add(gcId);
GridFormatRule gfrId = new GridFormatRule() { Name = "gfrId" };
// 指定应用到编号列
gfrId.Column = gcId;
gfrId.Rule = new FormatConditionRuleExpression()
{
// 使用Dev默认提供的预定义样式
PredefinedName = "Red Fill, Red Text",
Expression = "[Id] % 2 !=0 ", // Id值为奇数
};
// 是否应用到整行
//gfrId.ApplyToRow = true;
this.gv.FormatRules.Add(gfrId);
总结:
FormatRule的应用很大程度上方便的设置样式,而不用再使用RowStyle或者RowCellStyle 事件来进行Appearance的设置,而且这种设置容易导致页面不顺畅。TreeList与PivotGrid也有对应的Rule设置。