RowCellStyle 中的 DevExpress DisplayFormat
DevExpress DisplayFormat in RowCellStyle
正在切换应用程序以使用 DevExpress XtraGrid 并为 row/cells 实施自定义颜色和格式。
大多数部分格式都被正确应用。但是,当应用于格式为“#,###;(#,###);0”的小数 1000 时,最终结果为 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);
}
对于不使用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);
}
大多数部分格式都被正确应用。但是,当应用于格式为“#,###;(#,###);0”的小数 1000 时,最终结果为 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);
}
对于不使用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);
}