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

Custom Format

Hi,

I have a problem formating CellValue in GridControl QueryCellInfo.

codes like this:
e.Style.CellValue =0.000001;
e.Style.Format = "0.00%; -0.00%; - ";

the - will be shown for the final result. because this is the normal framework behavior.

However, I want the - to be displayed only when CellValue equals zero (before any formating). so I format values first using a customized codes, and then assign the formatted value to e.Style.FormattedText. this works for the diaplay purpose, however, it overwrites the CellValue with the FormattedText.

My question is, how to display a customized formatted value while CellValue still stores original value?

Thanks,

Q

4 Replies

QS Qingde Shi October 31, 2007 03:13 PM UTC

Hi,

I think I find a workaround.
instead of passing a custom format string to e.Style.Format, let framework to the conditional format, I pass it with a format based on e.Style.CellValue condition.

Regards,

Q


AD Administrator Syncfusion Team November 1, 2007 08:38 AM UTC

Another solution might be to use the DrawCellDisplayText event. There, you can set e.DisplayText to be anything you want and see it when the grid draws the cell contents. Setting e.DisplayText in this event has absolutely no effect on the style.CellValue, style.FormattedText, or anything else to do with the style. It only specifies the text the grid will draw in the cell. It is a 'safe' place to do custom formatting on the display string.


QS Qingde Shi November 6, 2007 03:24 PM UTC

Clay,

Thanks. How do you retrieve the value set to e.DisplayText in code?

Another question. How to allow user to change
cell value format in a virtual grid? I would guess one has to cache the format user set and over write the one set in QueryCellInfo event. Do you have an example? this question could also extend to other style infos, like font size, bold, alignment etc.

Thanks,

Q


>Another solution might be to use the DrawCellDisplayText event. There, you can set e.DisplayText to be anything you want and see it when the grid draws the cell contents. Setting e.DisplayText in this event has absolutely no effect on the style.CellValue, style.FormattedText, or anything else to do with the style. It only specifies the text the grid will draw in the cell. It is a 'safe' place to do custom formatting on the display string.



HA haneefm Syncfusion Team November 6, 2007 07:52 PM UTC

Hi Q,

Regarding the Issue 1: How do you retrieve the value set to e.DisplayText in code?
>>>>>>>>>>>>>>>>>>>>>>
There is no direct way to retrieve the text that is set for any cell in the DrawCellDisplayText event. The GridStyleInfo object associated with the cell does not hold any information on this. However, we may get this by having a hashtable with row and the colIndex as the hashcode key.

Regarding the Issue 2: How to allow user to change cell value format in a virtual grid?
>>>>>>>>>>>>>>>>>>>>>>
In a virtual grid, you are responsible for saving any cell style property you want to use.

So, if you want to change style.Format / BackColor for a cell, then in your SaveCellInfo hanlder, you will have to save this property, and then in QueryCellInfo, you have to retrieve the property you saved and set it back into the requested style.

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon