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

Formatting Cell Text

Hi,

I am using GGC. I am binding the entity collection to the grid. Grid contains some numeric columns having sales figures.
User Requirement is- When user select the formatting option as £K then i have to show values /1000 but my data source values should not get changed to /1000. I just need to change display text in cell to cell value/1000 keeping binded cell value as it is.
Is this possible in the GGC. Is there any property which store the formated text without changing the actual cell value..?
Please help.
Thanks
Harshad

3 Replies

HA haneefm Syncfusion Team May 29, 2007 05:23 PM UTC

Hi Harshad,

If you just want to format the text that is displayed, you can handle the TableControlDrawCellDisplayText and set e.DisplayText there to easily control what text is drawn in the cell.

void gridGroupingControl1_TableControlDrawCellDisplayText(object sender, GridTableControlDrawCellDisplayTextEventArgs e)
{
if (e.Inner.Style.CellType == "Currency")
{
if (e.Inner.Style.CellValue != null && e.Inner.Style.CellValue.ToString() != string.Empty )
{
double d;
double.TryParse(e.Inner.Style.CellValue.ToString(),out d) ;
e.Inner.DisplayText = string.Format("£{0}", d / 1000);
}
}
}

Best regards,
Haneef


HA Harshad July 9, 2007 02:47 PM UTC

Hi,

I tried the event but my cell is editable so when user click on the cell to edit the value ,cell display original value and not the formatted one.
What i want to do is user will enter value and i have to save the value *1000 in the datasource and in cell value will not be *1000. This is bounded column.
Please tell me how to do this. I always need to show value /1000 in the editable cell.


HA haneefm Syncfusion Team July 9, 2007 10:07 PM UTC

Hi Harshad.

If you want to display 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 default format. Here is a code snippet to show this

void TableModel_QueryCellFormattedText(object sender, Syncfusion.Windows.Forms.Grid.GridCellTextEventArgs e)
{
if (e.Style.CellType == "Currency")
{
if (e.Style.CellValue != null && e.Style.CellValue.ToString() != string.Empty)
{
double d;
double.TryParse(e.Style.CellValue.ToString(), out d);
e.Text = string.Format("£{0}", d / 1000);
e.Handled = true;
}
}
}

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon