I am currently using GridDataBoundGrid to display content of a table in my database.
One column of my data table is double type, which represents interest rate, for example:
I''d like to display them in a different format without modifying the data source, with percentage as unit, and only 2 decimals:
If I use the expression property in datacolumn, i''d have to create additional columns which i don''t really need.
Is there a better way to do it?
ADAdministrator Syncfusion Team November 12, 2004 10:10 AM
You can use QueryCellFormattedText. There you would set e.Text to be what you want to see in the see. Here is a little sample code that just formats a value - but you can set e.Text to anything you want.
private void gridControl1_QueryCellFormattedText(object sender, GridCellTextEventArgs e)
if(e.Style.CellValueType == typeof(double) && e.Style.Text.Length > 0)
double val = float.NaN;
if(e.Style.CellValue is string)
Double.TryParse((string)e.Style.CellValue, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out val);
val = (double)e.Style.CellValue;
e.Text = val.ToString("F3", e.Style.CultureInfo);
e.Handled = true;
Here is a small sample.
CWCheunhui WangNovember 15, 2004 09:05 AM
It looks like QueryCellFormattedText event is for GridControl only, and GridDataBoundGrid does not have this message. Is there a different event i can use?
Also, just another thought, When grid auto-sizes the columns, will grid be able to use the displayed text to determine column width? (this part is not that critical, just good to have)
ADAdministrator Syncfusion Team November 15, 2004 11:29 AM
This event is a member of the Model. So try the gridDataBoundGrid1.Model.QueryCellFormattedText event.
Yes, I think the text from this event should be used in grid.Model.ColWidths.ResizeToFit calls.
CWCheunhui WangNovember 15, 2004 12:03 PM
Yes, the event is found in the model, and it works as the way we wanted.