I am trying to set custom format of column within XtraGrid component:
public class Customers
{
public object A { get; set; }
}
Customers c61 = new Customers();
c61.A = DateTime.Now.AddDays(1);
Customers c62 = new Customers();
c62.A = DateTime.Now.AddDays(3);
List<Customers> tmpList = new List<Customers>();
tmpList.Add(c61);
tmpList.Add(c61);
gridControl1.DataSource = tmpList;
GridColumn gc = new GridColumn();
(gridControl1.MainView as GridView).Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] { gc });
gc.Caption = "A";
gc.FieldName = "A";
(gridControl1.MainView as GridView).Columns["A"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
(gridControl1.MainView as GridView).Columns["A"].DisplayFormat.FormatString = "dd/MM/yyyy";
It is not working. But when I simple remove adding column explicitly, XtraGrid automatically populates columns and format is working properly. Working code:
Customers c61 = new Customers();
c61.A = DateTime.Now.AddDays(1);
Customers c62 = new Customers();
c62.A = DateTime.Now.AddDays(3);
List<Customers> tmpList = new List<Customers>();
tmpList.Add(c61);
tmpList.Add(c61);
gridControl1.DataSource = tmpList;
(gridControl1.MainView as GridView).Columns["A"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
(gridControl1.MainView as GridView).Columns["A"].DisplayFormat.FormatString = "dd/MM/yyyy";