I am populating a WinGrid with data that needs to be formatted. For example, suppose my phonenumber field is 1234567890, i want this displayed at (123) 456-7890. To populate the grid i'm using custom business objects, the collection of which are passed into the SetDataBinding method of the grid.
I handle the formatting via the InitializeRow event, calling the SetValue method of the cell that I want to have formatted.
What i'm finding is that this formatting is being persisted back to the business object, which is messing me up.
How can I allow formatted text to be displayed in the grid but prevent that data from being saved to the underlying object? I've seen references to some sort of EditMode but i'm not sure how that's used and when/where I should set a property.
If you set the Value on the cell, then it will be written to the underlying data source. If you just want to format the value for display without changing the actual value in the cell, you can use the Format property of the column. When the grid displays the cell value, it calls the ToString method on the value and passes in the format you specify. So the format can be any format supported by the data type of the column.
Standard Numeric Format Strings
Custom Numeric Format Strings
That's valuable in many cases, including the one I gave. I gave a simplified example but let me give you the real one I'm trying to solve.
The column I'm displaying are credit card numbers. They are encrypted in the database but should be shown decrypted.
To accomplish this I call the decrypt routine on the cell in the InitializeRow method to display that result. Unfortunately the decrypted result is persisted back to the datasource, which causes issues for me later when I save a "record"
So I was hoping there was some way of setting what the display value should be, without affecting the underlying data.
To get around this I make a copy of the data into a different collection and bind that to the grid, but this is a short-term fix and I'm hoping there is a better way.