Miha Markic - DXSquad
12.07.2006
Hello Miha,
Merry Christmas and a Happy New Year!
The desired functionality can be implemented via an ICustomFormatter class. Here is the necessary code:
[C#]public class TuboFormatter : IFormatProvider, ICustomFormatter { public object GetFormat(Type formatType) { if(formatType == typeof(ICustomFormatter)) return this; else return null; } public string Format(string format, object arg, IFormatProvider formatProvider) { DateTime x = (DateTime)arg; return x.AddHours(-1).ToString(); } } ... this.gridView1.Columns[0].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom; this.gridView1.Columns[0].DisplayFormat.Format = new TuboFormatter();
It's also possible to create a more abstract formatter class, which will utilize the appropriate type converter for a given value. However, we advise against this solution, because it significantly impacts the grid's painting performance. That's the reason why we are not going to implement this feature in our XtraGrid. We've tested it and the cell painting performance has been dropped.
Another solution to your task is to implement the conversion in the getter and setter methods of your property:
[C#]public string MyConvertedDateTime { get { this.Date.AddHours(-1).ToString() } set { this.Date = DateTime.Parse(value); } }
The third solution is to create and use an unbound column for your data in the XtraGrid.
Thank you,
Nick