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

How to set currency cell in GGC

Hi,

I need to put currency cell in the GGC and need to put currency symbol in the GGC cell.I did that by setting the format property in the following GGC event.

void dgRangePlanGrid_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
e.Style.Format = "£##0.00"
}

this gives the entered value "25.00" in "£25.00" format which is correct.

Now when I select the cell,by mouse,it goes into the edit mode with displaying values as "£25.00",which is incorrect, because I need it to be dispaled as 25.00 after selection and once i edit and change the value say for ex 50.00 it should display againg back in the specified format with the currency symbol eg. "£50.00".

could you pls suggest some help and some code snippet would be very much appreciated.

Thanks,
Ejaz


5 Replies

AD Administrator Syncfusion Team June 7, 2007 03:43 PM UTC

One way to get this behavior is to use TableControlDrawCellDisplayText instead of QueryCellStyleInfo. Here is code that will format a column named "Amount" using this event.


void gridGroupingControl1_TableControlDrawCellDisplayText(object sender, GridTableControlDrawCellDisplayTextEventArgs e)
{
GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo;
if ((style.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell
|| style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)
&& style.TableCellIdentity.Column.Name == "Amount"
)
{
e.Inner.DisplayText = string.Format("{0:£##0.00}", style.CellValue);
}
}


EJ ejaz June 11, 2007 09:23 AM UTC


Hi,

Thanks for you prompt help.
That code is working,But I have two formats
1. "£##0.0" but value divided by thousand
2. "£##0.00"

Now if I have value in the grid in formats one("£##0.0") and two("£##0.00") it works fine but as soon as I click in the cell,it displays me the original value which was there in the grid before format.For example if I have value displayed earlier in the Grid like £25.00 it shows fine but when I apply format one("£##0.0") to show value in format "£##0.0" but divided by 1000(actually it shows the value in format one after dividing the sell value by 1000) it shows fine on the grid but when I click in the cell it shows me the old value £25.00 only which i dont need.I need it should show me the value which it shows after applying the format say £0.0("£##0.0") bacause after dividing 25/1000 we get 0.025 and in the format ("£##0.0") it should show £0.0 and when I click in the cell it should show £0.0 and not £25

Regds,
Ejaz


>One way to get this behavior is to use TableControlDrawCellDisplayText instead of QueryCellStyleInfo. Here is code that will format a column named "Amount" using this event.


void gridGroupingControl1_TableControlDrawCellDisplayText(object sender, GridTableControlDrawCellDisplayTextEventArgs e)
{
GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo;
if ((style.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell
|| style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)
&& style.TableCellIdentity.Column.Name == "Amount"
)
{
e.Inner.DisplayText = string.Format("{0:£##0.00}", style.CellValue);
}
}



RA Rajagopal Syncfusion Team June 13, 2007 12:48 AM UTC

Hi Ejaz,

The reason for this behavior is that, the TableControlDrawCellDisplayText is just for the display purpose. So, when the cell enters edit mode while you click on the cell it will show the underlying cellvalue and not the displaytext. This is the default behavior. You can try the below property setting to avoid cell getting into edit mode when clicking on the cell, there by retaining the format for the currentcell.

this.gridGroupingControl1.TableModel.Options.ActivateCurrentCellBehavior = GridCellActivateAction.DblClickOnCell;

Let us know if this helps.
Regards,
Rajagopal


- - May 5, 2008 09:32 AM UTC

I have a case where the currency is 0.0000000.
I need to set such value to "$0.00" by a format string. The format string "$#.##" displays the result as "$" only.
What is the solution to display the value as "$0.00" please? Thanks.



AD Administrator Syncfusion Team May 6, 2008 03:44 PM UTC


Hi MB,

You can set the fomat of your cell to display "$0.00" with the help of the following code.


private void Form1_Load(object sender, EventArgs e)
{
this.gridControl1.ColStyles[1].Text = "000";
this.gridControl1.ColStyles[1].Format = "C";
this.gridControl1.ColStyles[1].CellValueType = typeof(double);
}


Please refer the sample in the below link that illustrates the above.

http://websamples.syncfusion.com/samples/Grid.Windows/F62088/main.htm

Please let me know if you have any questions.

Regards,
Asem.


Loader.
Live Chat Icon For mobile
Up arrow icon