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.
Unfortunately, activation email could not send to your email. Please try again.

GridDataBoundGrid Formatting Data for display only

Thread ID:

Created:

Updated:

Platform:

Replies:

21514 Nov 12,2004 09:23 AM Nov 15,2004 12:03 PM Windows Forms 4
loading
Tags: GridControl
Cheunhui Wang
Asked On November 12, 2004 09:23 AM

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

Cheunhui Wang
Replied On 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

Administrator [Syncfusion]
Replied On 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.

Cheunhui Wang
Replied On 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

CONFIRMATION

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.

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.

;