DevExpress DisplayFormat в RowCellStyle

введите описание изображения здесьПереключение приложения на использование DevExpress XtraGrid и реализация настраиваемого цвета и формата для строк/ячеек.

По большей части форматы применяются правильно. Однако при применении к десятичному числу 1000 в следующем формате "#,###;(#,###);0" получается 1000.0000 вместо 1000.

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);

 }

person Boris Kleynbok    schedule 08.03.2017    source источник


Ответы (1)


Для связанных столбцов, которые не используют CustomColumnDisplayText, необходимо установить FormatType перед установкой DisplayFormatString.

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);
}
person Boris Kleynbok    schedule 08.03.2017