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. Image for the cookie policy date

GridDataBoundGrid Formatting Data for display only

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: 0.0233333 0.0244444 I''d like to display them in a different format without modifying the data source, with percentage as unit, and only 2 decimals: 2.33 2.44 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? Thanks, Chunhui

4 Replies

AD Administrator 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); else val = (double)e.Style.CellValue; e.Text = val.ToString("F3", e.Style.CultureInfo); e.Handled = true; } } Here is a small sample.


CW Cheunhui Wang November 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) Thanks, Chunhui


AD Administrator 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.


CW Cheunhui Wang November 15, 2004 12:03 PM

Yes, the event is found in the model, and it works as the way we wanted. Thanks much! Chunhui

Loader.
Live Chat Icon For mobile
Up arrow icon