• Devexpress Winform Gridcontrol 中根据条件单元格的值改变单元格的颜色等属性。


    提供一下三种方法

    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 应收预警
            }
    View Code

        

     3.在绘制行或者单元格时候设置

    示例代码1:

      private void bandedGridViewSalesDailyReport_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
            {
                Color c = System.Drawing.Color.FromArgb(((int)(((byte)(253)))), ((int)(((byte)(234)))), ((int)(((byte)(218)))));
    
                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;
                }
            }
    View Code

     示例代码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;
                    }
                }
            }
    View Code
  • 相关阅读:
    使用 JavaScript 将 Silverlight 添加到网页
    网络和通信 Silverlight 中的 HTTP 通信和安全
    在Silverlight中访问Web服务 为 Silverlight 客户端生成服务
    图形三维效果
    关键帧动画
    ajax.dll 与 ajaxpro.dll的用法[摘自网络]
    FlashObject.js去虚框、传参数、获取URL参数
    WEB标准之CSS: 打造自己的重置样式reset.css[转]
    jquery.cookie.js[保存]
    FCKeditor在.net中详细配置[摘自网络]
  • 原文地址:https://www.cnblogs.com/yuanjiedao/p/4727339.html
Copyright © 2020-2023  润新知