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
close icon

GridBoundDataGrid and Number Formatting

Hello,

I am binding a GridBoundDataGrid to a custom object which has a property of type Double. The property is to be stored in the underlying database as the actual value; however, from the front-end, I have a requirement to show the number in millions, as well as receive input in millions.

For example, if the actual value is [1,000,000,000]
the grid should accept and display
[1,000]
as the cell value. The underlying object, however, should maintain
[1,000,000,000]
in its property.

I am currently using the Model.QueryCellInfo to successfully manipulate the value for display purposes, but the Model.SaveCellInfo is not giving me the same success when attempting to persist back into the data source.

Any recommendations? Thanks.

2 Replies

AD Administrator Syncfusion Team September 21, 2006 04:25 AM UTC

Hi John,

You can handle the DrawCellDisplayText event of the grid and set the e.DisplayText to some new value to want to display. Use the e.Style.CellIdentity.RowIndex and e.Style.CellIdentity.ColIndex to get the row and column of the cell for which the displaytext has to be set. Below is a code snippet.

private void DrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e)
{
if(e.Style.CellIdentity.ColIndex == 1 && e.Style.CellIdentity.RowIndex > 0 && e.DisplayText != null && e.DisplayText != string.Empty )
{
double dvalue = Double.Parse(e.Style.CellValue.ToString());
e.DisplayText = String.Format("{0:#,##0,,.0MB}",dvalue) ;
}
}

Let me know if this helps.

Best Regards,
Haneef


AD Administrator Syncfusion Team September 21, 2006 01:10 PM UTC

Hi Haneef,

Thank you, but that is not quite what I''m looking for. I want the value to be displayed and input in millions, but I want the grid to convert the value and store it in the underlying data source as the actual value.

For example, when the user sees [1,000] in the grid, the underlying value is [1,000,000,000] (i.e. the display value times one million). The user should then be able to change the cell value to [2,000], which would have the effect of persisting [2,000,000,000] to the underlying data source. Both the display and the input should be properly transformed when interacting with the data source.

Thanks for your continued assistance.

>Hi John,

You can handle the DrawCellDisplayText event of the grid and set the e.DisplayText to some new value to want to display. Use the e.Style.CellIdentity.RowIndex and e.Style.CellIdentity.ColIndex to get the row and column of the cell for which the displaytext has to be set. Below is a code snippet.

private void DrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e)
{
if(e.Style.CellIdentity.ColIndex == 1 && e.Style.CellIdentity.RowIndex > 0 && e.DisplayText != null && e.DisplayText != string.Empty )
{
double dvalue = Double.Parse(e.Style.CellValue.ToString());
e.DisplayText = String.Format("{0:#,##0,,.0MB}",dvalue) ;
}
}

Let me know if this helps.

Best Regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon