I am trying to display UTC dates as local time in my grid. I subclassed the grid, and have it add an unbound column for each date column to display the local time. I copy all the column settings to this column, and then rename and hide the original column. I calculate the local time inside 'OnInitializeRow'
It all works great.. until I update the datasource the grid is based on. OnInitializeRow doesn't run and so the date stays at the old value. Right now I added a function that gets manually called after I update the datasource to go through all the cells in the grid and update them if they are my unbound local time cells.
Is there a cleaner/faster/better way of doing this?? I really wish there was support in the infragistics controls to display dates according to the regional settings.. there is regional support for all the other editors and values.
Works great.. I am attaching what I wound up using in case it helps someone else.
Since we have a convention of storing dates in the database as UTC, this is a subclassed grid with a property you can set to make it assume all date values are UTC and display them in local time.
Oh wow I think you may have saved me here.. I am running into some pretty bad problems with the 'hidden column' approach and columns that were bound to class properties calculated from the date.
Giving it a try.
You got me curious about whether this was feasible...I attached a demo app that shows how to do it using the IEditorDataFilter approach.
Thanks.. what I mean is, other values are displayed based on workstation settings, it seems like it would be natural to have the ability to display the date based on the workstation time zone.
I didn't know about UltraGridColumn.Editor.DataFilter, it sounds like this is the way to go. If I can scrape together some more time to revisit this I am going to give it a try..
jeffkov said:Is there a cleaner/faster/better way of doing this?? I really wish there was support in the infragistics controls to display dates according to the regional settings.. there is regional support for all the other editors and values.
The problem you describe is not a function of regional formatting, but rather the conversion from UTC to local time. The date/time formatting properties exposed by the culture settings are not associated with a time zone, because there is not a one-to-one relationship between a time zone and a culture.
The problem you are trying to solve here sounds like a good fit for the IEditorDataFilter interface (see the UltraGridColumn.Editor.DataFilter property). That interface gives you the opportunity to convert the values as they go back and forth from the editor to the cell. Your implementation would take the date/time as UTC, and convert it to local time before presenting it to the user, then convert back before assigning the value to the cell.