悟天的小别墅

人心忧虑,屈而不升。 一句良言,使心欢喜。

导航

VGridControl中DisplayFormat的问题

Posted on 2012-03-13 15:41  marcozh  阅读(6053)  评论(0编辑  收藏  举报

 

这两天用VGridControl,有个界面是根据参数需要动态生成行和对应的编辑控件。我想根据参数中的单位来格式化显示效果,如把5显示成5.00 KG。

在Runtime中写入如下语句:

 editor.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
editor.DisplayFormat.FormatString = "0.00 " + property.Unit;

但是却无法得到想要的效果,查看了文档后之后才发现,原来绑定的源数据中的DataTable字段都被我设成了string类型,必须要改成对于的字段类型才可以

 

DataColumn col = new DataColumn();
col.ColumnName = property.Id.ToString();
if (property.DataType == (int)DataType.Int)
col.DataType = typeof(int);
else if (property.DataType == (int)DataType.Float)
col.DataType = typeof(float);
else if (property.DataType == (int)DataType.Datetime)
col.DataType = typeof(DateTime);
else if (property.DataType == (int)DataType.Bool)
col.DataType = typeof(bool);
else
col.DataType = typeof(string);
dtProperty.Columns.Add(col);


这样就显示正确了