1.最简单的方式,在控件列属性里设置,注(列的控件类型必需设为FLEX自带的那种才行), 有FORMAT CONDITION 可以设置,包括色彩等。一列只能定义一种规则。
2. 实现CellFactory ,自定义规则
public class ConditionalCellFactory : CellFactory
{
public override void ApplyCellStyles(C1FlexGrid grid, CellType cellType, CellRange rng, System.Windows.Controls.Border bdr)
{
base.ApplyCellStyles(grid, cellType, rng, bdr);
if ((cellType == CellType.Cell) && (rng.Column == 13)) // 对第几列处理
{
var row = grid.Rows[rng.Row];
var cst = row.DataItem as OrderDetailExecuteDataItem; //获取当前行的实际对象值转一下
if (cst != null)
{
if (cst.DeliveryDate.Date > DateTime.Today)
bdr.Background = new SolidColorBrush(Colors.Blue);
else
bdr.Background = new SolidColorBrush(Colors.Red);
}
}
}
}
partial void FlexibleOrderDetailExecuteDataBySupplierIDGrid_Created()
{
IContentItemProxy proxy = this.FindControl("C1FlexGrid");
proxy.ControlAvailable += (s, e) =>
{
var fg = e.Control as C1FlexGrid;
if (fg != null)
{
fg.CellFactory = new ConditionalCellFactory();
}
};
}
3. 直接调用现有条件格式类(和第一个本质是一样,只是后台用代码实现,但可以定义多个规则)
void proxy_ControlAvailable(obje