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.

GridBoundDataGrid and Number Formatting

Thread ID:

Created:

Updated:

Platform:

Replies:

49532 Sep 20,2006 04:03 PM Sep 21,2006 09:10 AM Windows Forms 2
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On September 20, 2006 04:03 PM

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.

Administrator [Syncfusion]
Replied On September 21, 2006 12:25 AM

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

Administrator [Syncfusion]
Replied On September 21, 2006 09:10 AM

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

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.

;