![](/img/trans.png)
[英]Set DisplayFormat and EditFormat for DevExpress TextEdit
[英]DevExpress DisplayFormat in 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);
}
對於不使用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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.