gpt4 book ai didi

devexpress - 如何格式化列以显示Xtragrid中的百分比(%)

转载 作者:行者123 更新时间:2023-12-04 05:14:08 32 4
gpt4 key购买 nike

我有一个存储过程中的值的xtragrid。
我正在浮点数(0.23)中获取值,我想以百分比(23%)显示。
用C#做到这一点的最佳方法是什么?



最佳答案

如果只想以只读方式显示单元格,则使用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() + "%";
}
}

另一种方法是使用编辑器的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";

希望能有所帮助。

关于devexpress - 如何格式化列以显示Xtragrid中的百分比(%),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10682522/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com