DevExpress XtraGrid 单元格上的小数
Decimal numbers on DevExpress XtraGrid cells
我有一个 DevExpress XtraGrid 控件,我想在其中的一个单元格中放入一个十进制数,但是当我尝试从一个单元格跳到另一个单元格时,它不让我这样做,除非我再次更改数为整数。
我已经像这样修改了设计中的属性:
[
什么也没发生,同样在 Form.Load 事件中,我以编程方式设置了这个 属性,但似乎不起作用。
colnBase.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric
colnBase.DisplayFormat.FormatString = "{0:N4}"
我已经查看了 DevExpress 论坛,但我找不到答案,这是我在这里的第一个问题,所以如果你们中的任何人能帮助我,我将不胜感激。
您在基础数据源中使用了错误类型的值。 nBase
字段中的值必须是浮点数类型之一,例如 Single
、Double
、Decimal
等
这是示例:
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}"
我修复了 "problem",错误是我从视图中收取数据并且所有产品记录返回为 0
select 0 as data1, 0 as data2 from Table
但似乎 SQL 返回整数形式的数字,我无法修改 XtraGrid 中的值,即使它在 DataTable 和 XtraGrid 中被声明为 Decimal 或 Numeric。
我是这样修复的:
select convert(decimal(18,4),0) as data1, convert(decimal(18,4),0) as Data2 from Table
感谢大家的回答,我希望其他人能从我的错误中受益。
我有一个 DevExpress XtraGrid 控件,我想在其中的一个单元格中放入一个十进制数,但是当我尝试从一个单元格跳到另一个单元格时,它不让我这样做,除非我再次更改数为整数。 我已经像这样修改了设计中的属性:
[
什么也没发生,同样在 Form.Load 事件中,我以编程方式设置了这个 属性,但似乎不起作用。
colnBase.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric
colnBase.DisplayFormat.FormatString = "{0:N4}"
我已经查看了 DevExpress 论坛,但我找不到答案,这是我在这里的第一个问题,所以如果你们中的任何人能帮助我,我将不胜感激。
您在基础数据源中使用了错误类型的值。 nBase
字段中的值必须是浮点数类型之一,例如 Single
、Double
、Decimal
等
这是示例:
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}"
我修复了 "problem",错误是我从视图中收取数据并且所有产品记录返回为 0
select 0 as data1, 0 as data2 from Table
但似乎 SQL 返回整数形式的数字,我无法修改 XtraGrid 中的值,即使它在 DataTable 和 XtraGrid 中被声明为 Decimal 或 Numeric。
我是这样修复的:
select convert(decimal(18,4),0) as data1, convert(decimal(18,4),0) as Data2 from Table
感谢大家的回答,我希望其他人能从我的错误中受益。