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

Cell Formatting

I see that I can format numeric (double) data myself, or use the GridStyleInfo.format to setup a string for formatting cell data. We need to be able to:

1. Format the display of the numeric cell data depending on the number of decimal places specified once the user enters a value.

2. Display the original unformatted number when the user clicks into the cell to edit the value.

We are using virtual grids. Can you tell me the best way to accomplish this?

5 Replies

AD Administrator Syncfusion Team February 5, 2007 09:40 PM UTC

Hi Kyle,

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 = string.Format("{0:P}" , int.Parse(e.Style.CellValue.ToString( ) ) );
}

Best Regards,
Haneef


KD Kyle DeVoe February 5, 2007 10:15 PM UTC

Haneef,

Thanks. That seems to do the trick.

Kyle


KD Kyle DeVoe March 13, 2007 12:55 PM UTC

Haneef,

As a follow up question, I resize columns to fit after a cell is deactivated. Currently, when I resize to fit, it resizes on the style text, not the display text. If I format a number, say
123.456789 to two decimal places, the display text correctly shows 123.45. The resize to fit of the column uses 123.456789, so the column is too wide. Is there a way to force a column resize on the displayed text?

thanks,
Kyle


AD Administrator Syncfusion Team March 13, 2007 07:59 PM UTC

Hi Kyle,

Thanks for your update.

The reason for getting this behavior is that you are using the DrawCellDisplayText event to set the text format. The DrawCellDisplayText event does not store any styleInfo properties in a grid. It just set the visual apperence of the grid. The ResizeToFit method resizes a range of rows or columns to optimally fit stored contents of the specified range of cells in grid. It depends on the data stored in a grid. If the grid doesn't have any data, ResizeToFit method doesn't make any changes in a grid. If you want to store the formatted text in a cell then subscribe the QueryCellFormattedText event and set the e.Text to your new formatted value and then set e.Handled to TRUE to cancel it.

this.gridDataBoundGrid1.Model.QueryCellFormattedText +=new GridCellTextEventHandler(Model_QueryCellFormattedText);

private void Model_QueryCellFormattedText(object sender, GridCellTextEventArgs e)
{
e.Text = "ResizeToFit example here...";
e.Handled = true;
}

Best regards,
Haneef


KD Kyle DeVoe March 20, 2007 03:45 PM UTC

Haneef,

I think the info you have provided will work for me.

One more question, is there a way to go the reverse of what you described in your last post? If the user clicks into the cell for editing, how can I redisplay the unformatted value in the cell?

thanks,
Kyle

Loader.
Live Chat Icon For mobile
Up arrow icon