【问题标题】:DevExpress DisplayFormat in RowCellStyleRowCellStyle 中的 DevExpress DisplayFormat
【发布时间】:2017-03-08 18:33:52
【问题描述】:

Switching 应用程序使用 DevExpress XtraGrid 并为行/单元格实现自定义颜色和格式。

大部分格式都被正确应用。但是,当应用于十进制 1000 时,格式为 "#,###;(#,###);0" 最终是 1000.0000 而不是 1,000。

gridView.RowCellStyle += CellFormatting;
private void CellFormatting(object sender, RowCellStyleEventArgs e)    
 {
        if (gridView.IsRowSelected(e.RowHandle))
        {
            e.Appearance.BackColor = SystemColors.Highlight;
            e.Appearance.ForeColor = SystemColors.HighlightText;
            return;
        }

        // get cell by its index
        var gridRow = gridView.GetRow(e.RowHandle);
        TLColumn columnEnum = ((BindableTextBoxColumn)e.Column).ColumnEnum;
        // get new format values 
        T row = (T)gridRow;

        e.Column.DisplayFormat.FormatString = row.GetCellFormat(columnEnum);
        e.Appearance.BackColor = row.GetCellBackColor(columnEnum);
        e.Appearance.ForeColor = row.GetCellColor(columnEnum);

 }

【问题讨论】:

    标签: winforms devexpress decimal xtragrid displayformat


    【解决方案1】:

    对于不使用CustomColumnDisplayText的绑定列,需要在设置DisplayFormatString之前设置FormatType。

    e.Column.ColumnType 
    

    可以显示绑定属性的类型

     private void CellFormatting(object sender, RowCellStyleEventArgs e)
     {
           // get cell by its index
            var gridRow = gridView.GetRow(e.RowHandle);
            var column = (BindableTextBoxColumn)e.Column;
            TLColumn columnEnum = column.ColumnEnum;
            // get new format values 
            T row = (T)gridRow;
    
            e.Column.DisplayFormat.FormatType = (column.IsNumeric) ? FormatType.Numeric : column.DisplayFormat.FormatType;
            e.Column.DisplayFormat.FormatString = row.GetCellFormat(columnEnum);
            if (gridView.IsRowSelected(e.RowHandle))
            {
                e.Appearance.BackColor = SystemColors.Highlight;
                e.Appearance.ForeColor = SystemColors.HighlightText;
                return;
            }
            e.Appearance.BackColor = row.GetCellBackColor(columnEnum);
            e.Appearance.ForeColor = row.GetCellColor(columnEnum);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-26
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多