I have a xtragrid with values from a stored procedure.
I am getting the values in float (0.23) and I want to display in percent (23%).
What would be the best way to do it in C#?  
before
 after
after

Use CustomDrawCell event if you just want to display the cell readonly. or You can use the CustomColumnDisplayText Event also.
Try this:
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() + "%";
                }
            }
Another way use the Editor EditFormat and DisplayFormat property. and after setting these properties add it to the gridview column: 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;
        }
The simplest way is use GridColumn.DisplayFormat Property.
colPayment.DisplayFormat.FormatType = FormatType.Numeric;
colPayment.DisplayFormat.FormatString = "p0";
Hope this help..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With