Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1500
Currency format for selected non-numeric cell value
posted

Hi all,

I'm using a custom type for cells values of the grid (say CustomCell). When the grid is rendered it calls the CustomCell.ToString() method. So, the only thing I need is to override the ToString method of the CustomCell class. The CustomCell objects represent only numeric values.

Now we have a requirement to show some cells of the same column in a currency format ("$nnn.nn")  and some cells still in a "regular" format. That would be logically to set for some cells the Currency style. However, this will not work, because I'm not using numeric values as cells values.

 Is there a simple way some cells of the same column can be in the currency format while other ones in "regular"? I would like to change the CustomCell only by implementing IFormattable.

 Thanks,

Vitaly

 

  • 469350
    Verified Answer
    Offline posted

    There's really no simple way to format different cells in the same column with different formats. 

    One way you could do this is with a DrawFilter - this would allow you to draw the text in the cell yourself. I assume the cell is not updatable by the user. 

    Another optoion would be to use a DataFilter. The advantage to this approach is that you don't have to get involved in drawing text with GDI+. The disadvantage is that you need to convert the text both ways - formatting it and then unformatting it. 

    Still another option would be to use a CreationFilter and change the text of the TextUIElement in the cell. 

    And still another option would be to hide the real bound column in the grid, add an Unbound column, and then use the InitializeRow event to populate the unbound column with the formatted text you want, based on the value of the bound column in the same row. This last approach is probably the easiest.