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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Cell Formatting

Thread ID:

Created:

Updated:

Platform:

Replies:

55828 Feb 5,2007 09:21 PM UTC Mar 20,2007 03:45 PM UTC WinForms 5
loading
Tags: GridControl
Kyle DeVoe
Asked On February 5, 2007 09:21 PM UTC

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?

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

Kyle DeVoe
Replied On February 5, 2007 10:15 PM UTC

Haneef,

Thanks. That seems to do the trick.

Kyle

Kyle DeVoe
Replied On 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

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

Kyle DeVoe
Replied On 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

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.

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

;