We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

databound grid: sorting strings (percentage) as floats

Thread ID:





54864 Jan 18,2007 09:38 PM UTC Jan 19,2007 03:19 PM UTC WinForms 4
Tags: GridControl
Nick M
Asked On January 18, 2007 09:38 PM UTC


I have a databound grid. One of the columns displays percentages. I keep the DataColumn.DataType as a float so that I can sort it. However, I'd like the display to have a '%' after the number. I can't figure out a way to do this without storing the value as a string. If I do this, the sorting is broken.

Any ideas?


Administrator [Syncfusion]
Replied On January 18, 2007 10:35 PM UTC

I think I figured this out. In the CellDrawn event handler I do the following:

float val =(float) mygrid[e.RowIndex, e.ColIndex].CellValue;
Brush brush = new SolidBrush(e.Style.BackColor);
e.Graphics.FillRectangle(brush, e.Bounds);
e.Graphics.DrawString(val.ToString("F1") + "%", e.Style.Font.GdipFont, new SolidBrush(e.Style.TextColor), e.Bounds.Location);
e.Cancel = true;


hope that formatted okay.

Anyway, this seems to work. If there is a better way, please let me know


Administrator [Syncfusion]
Replied On January 18, 2007 10:36 PM UTC

Hi Nick,

If you want to format the cell, then use StyleInfo.Format property to set percentage format in the grid. Here is a code snippet.

this.gridDataBoundGrid1.Binder.InternalColumns[ColumnName].StyleInfo.CellValueType = typeof(float);
this.gridDataBoundGrid1.Binder.InternalColumns[ColumnName].StyleInfo.Format = "P";

Do you want to display the percentage at the end of the cell content without storing it? If yes, you can use DrawCellDisplayText event and set the e.DispalyText to some new value to want to display. Here is a code snippet

private void gridDrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e)
if( e.ColIndex == 3 && e.RowIndex >0)
e.DisplayText = e.Style.Text +"%";

Best Regards,

Replied On January 19, 2007 06:24 AM UTC

Hi haneef!

I dont have ColIndex property in the DrawcellDisplaytext event.then how to make the value in the cell display with the % symbol.

pls help.



Administrator [Syncfusion]
Replied On January 19, 2007 03:19 PM UTC

Hi Dhana,

Try this code snippet to get the ColIndex / RowIndex from the GridDrawCellDisplayTextEventArgs.

int ColIndex = e.Style.CellIndentity.ColIndex;
int ColIndex = e.Style.CellIndentity.RowIndex;

Best Regards,


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon