【发布时间】:2012-05-21 09:18:35
【问题描述】:
我有一个 xtragrid,其中包含来自存储过程的值。
我得到浮点数 (0.23) 的值,我想以百分比 (23%) 显示。
在 C# 中最好的方法是什么?
之前 后
【问题讨论】:
标签: devexpress xtragrid
我有一个 xtragrid,其中包含来自存储过程的值。
我得到浮点数 (0.23) 的值,我想以百分比 (23%) 显示。
在 C# 中最好的方法是什么?
之前 后
【问题讨论】:
标签: devexpress xtragrid
如果您只想以只读方式显示单元格,请使用 CustomDrawCell 事件。或者您也可以使用CustomColumnDisplayText Event。
试试这个:
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (e.Column.FieldName == "Marks")
{
e.DisplayText = (((int)(Convert.ToDecimal(e.CellValue) * 100))).ToString() + "%";
}
}
另一种方法是使用Editor EditFormat 和DisplayFormat 属性。并在设置这些属性后将其添加到 gridview 列:参考:How to format values shown in the XtraGrid
RepositoryItem textEdit;
private void AddGridRepositoryItem()
{
textEdit = new RepositoryItemTextEdit();
textEdit.AllowHtmlDraw = DevExpress.Utils.DefaultBoolean.True;
textEdit.ReadOnly = true;
gridControl1.RepositoryItems.Add(textEdit);
textEdit.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
textEdit.DisplayFormat.FormatString = "p";
gridView1.Columns[0].ColumnEdit = textEdit;
}
最简单的方法是使用GridColumn.DisplayFormat 属性。
colPayment.DisplayFormat.FormatType = FormatType.Numeric;
colPayment.DisplayFormat.FormatString = "p0";
希望对您有所帮助..
【讨论】:
请使用以下方法:
colReabilitation.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
colReabilitation.DisplayFormat.FormatString = "p0";
相关链接:
【讨论】:
P 将其视为50 as 50%,如果你想使用比例0 to 1,则必须在格式字符串中使用小p..