Hello! I must to say that this forum is very helpfull.
I have some columns with DateTime that are retrieved from DB in UTC.
Threre is some options to show them in grid in local tome? I found only way to format the date...
Thanks a lot!
WinGrid has no built-in functionality to handle date conversion. If your underlying data contains time expressed in UTC, then the grid will show it in UTC.
There are two options. One is to translate the data to local time in your underlying data source (and, of course, to translate it back before storing these DateTime values back to the database). The other is to use a DataFilter on the grid to perform the translation each time the data is requested and updated. I suggest the first option; it's less code to write, and will only affect performance when interacting between your data source and the database.
I tried to convert date on InitializeRow this way:
private void UgSystem_InitializeRow(object sender, InitializeRowEventArgs e) { if (e.ReInitialize) return; var utc = (DateTime)e.Row.Cells["LastModified"].Value; e.Row.Cells["LastModified"].Value = utc.ToLocalTime(); }
The problem I have now is pencil icon. How can I get rid of it?
After you set the value of the cell, commit the change to the row:
e.Row.Update();
Thanks Mike, it worked!