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
275
Formatting WinGrid cells without persisting
posted

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.

Parents
  • 469350
    Suggested Answer
    Offline posted

    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

Reply Children