[英]Set GridControl column format programmatically (DevExpress)
I have a GridControl made by code: 我有一个通过代码制作的GridControl:
GridControl gc= new GridControl();
gc.Name = "Grid1";
gc.AutoGenerateColumns = AutoGenerateColumnsMode.AddNew;
gc.ItemsSource = myDataTable;
The problem is that I have a column called "creation_time", and I want to change the default detetime format from dd/mm/yyyy to dd/mm/yyyy HH:MM:SS. 问题是我有一个名为“ creation_time”的列,并且我想将默认的detetime格式从dd / mm / yyyy更改为dd / mm / yyyy HH:MM:SS。
I'm trying to create a GridColum from the GridControl but I don't know if it's the right way 我正在尝试从GridControl创建GridColum,但是我不知道这是否是正确的方法
GridColumn colCurrency = gc.Columns["creation_time"];
colCurrency.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
colCurrency.DisplayFormat.FormatString = "G";
I think the problem is that you use auto create column and in myDataTable has the variable type DateTime that creates a DateTime column (format without timespan). 我认为问题是您使用了自动创建列,并且myDataTable中的变量类型DateTime创建了DateTime列(无时间跨度的格式)。 One solution is not to use AutoCreateColumn and create them manually, and then you can set the display options (formatString...) how you write
一种解决方案是不使用AutoCreateColumn并手动创建它们,然后可以设置显示方式(formatString ...)编写方式
最后我做到了:
gc.Columns["creation_time"].EditSettings = new TextEditSettings() { DisplayFormat = "{G}" };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.