Sử dụng CustomDrawCell sự kiện nếu bạn chỉ muốn hiển thị các tế bào chỉ đọc. hoặc Bạn cũng có thể sử dụng số CustomColumnDisplayText Event.
Hãy thử điều này:
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() + "%";
}
}
Một cách khác sử dụng tài sản biên tập EditFormat và DisplayFormat. và sau khi cài đặt các thuộc tính bổ sung nó vào cột GridView: Ref: 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;
}
Cách đơn giản nhất là sử dụng GridColumn.DisplayFormat tài sản.
colPayment.DisplayFormat.FormatType = FormatType.Numeric;
colPayment.DisplayFormat.FormatString = "p0";
Hope trợ giúp này ..
Nguồn
2012-05-21 10:48:55
Đó chính xác là những gì tôi đang tìm kiếm. 1 cho tất cả các tham chiếu. – Stavros
Đẹp, và điều này cũng cho phép tôi lưu trữ phần trăm như byte/tinyint - cảm ơn! Nếu không GridControl đã không giải thích dữ liệu như tôi muốn -> 10 phần trăm biến thành 1000% :) – Prokurors
Tại sao trên trái đất này là câu trả lời được chấp nhận? – Aron