2016-04-01 29 views
0

我有一个DevExpress XtraGrid控件,我想将一个十进制数字放在其中一个单元格中,但是当我尝试从单元格跳转到另一个时,它只是不让我,除非我再次更改该数字的值为一个整数。 我已经修改了从设计到性能是这样的:DevExpress XtraGrid单元格上的十进制数字

[Image of designer]

什么都没有发生,也会在Form.Load事件中,我以编程方式设置此属性,但它似乎只是不工作。

colnBase.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric 
colnBase.DisplayFormat.FormatString = "{0:N4}" 

我已经检查了DevExpress的论坛,但我无法找到答案,这是我的第一个问题在这里,所以如果你们可以帮助我,我真的很感激它。

+0

所以格式工作,它只是希望你输入一个无小数位的整数,如果你试图离开单元格这个数字是在?你是否使用任何类型的掩码输入? – dcreight

+0

不,我所配置的只是DisplayFormat,但是当我尝试将小数点放在单元格上时,它只是不让我。我的数据表具有与设计者相同的数据类型,所以这不是问题。 –

+0

是否:'colnBase.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom colnBase.DisplayFormat.FormatString =“n4”'work?我在DevExpress的一个更老版本中使用它,似乎工作正常。 – dcreight

回答

0

我固定的“问题”,这个错误是我是从查看计费数据,所有产品返回的记录为0

select 0 as data1, 0 as data2 from Table 

但似乎SQL返回整型数,我能不能够,甚至modificate在XtraGrid中的价值,当它被宣布为十进制或DataTable中的Numeric和XtraGrid中。

我固定它是这样的:

select convert(decimal(18,4),0) as data1, convert(decimal(18,4),0) as Data2 from Table 

谢谢你们回答,我希望从我的错误别人的利益。

0

您在底层数据源中使用了错误的值类型。在nBase字段中的值必须是浮点数类型像Single之一,DoubleDecimal
这里是例子:

Dim table = New DataTable() 

table.Columns.Add("ID", GetType(Int32)) 
table.Columns.Add("Value", GetType(Single)) '<= If you change the type to Int32 
' then you will not be able to write floating-point number into your cell 

table.Rows.Add(0, 0) 
table.Rows.Add(1, 1.1) 

gridControl.DataSource = table 

gridView1.PopulateColumns() 

Dim displayFormat = gridView1.Columns("Value").DisplayFormat 
displayFormat.FormatType = FormatType.Numeric 
displayFormat.FormatString = "{0:N4}" 
+0

数据集中的系统数据类型为网格的十进制。 –

+0

@MartinOmarUriasLópez所以,根据你的[答案](http://stackoverflow.com/a/36414783/1805640),你的底层数据源中有'Int32'值(在你的案例中是'DataTable')。 – nempoBu4

+0

是的,但我当时无法弄清楚,因为在我的设计数据集中,我已经将值设置为Decimal,而我的基本想法是DS会将值转换为Decimal,因为它已经在DS中声明了。 –

相关问题