VGridControl中DisplayFormat的问题


 

这两天用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);


这样就显示正确了

 


 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM