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

GridDataBoundGrid Formatting Data for display only

Thread ID:





21514 Nov 12,2004 02:23 PM UTC Nov 15,2004 05:03 PM UTC WinForms 4
Tags: GridControl
Cheunhui Wang
Asked On November 12, 2004 02:23 PM UTC

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

Administrator [Syncfusion]
Replied On November 12, 2004 03:10 PM UTC

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.

Cheunhui Wang
Replied On November 15, 2004 02:05 PM UTC

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

Administrator [Syncfusion]
Replied On November 15, 2004 04:29 PM UTC

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.

Cheunhui Wang
Replied On November 15, 2004 05:03 PM UTC

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


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