little m
little m

Reputation: 113

Decimal numbers on DevExpress XtraGrid cells

I have a DevExpress XtraGrid control in which I wanna put a decimal number in one of the cells, but when I try to jump from a cell to another it just not let me, unless I change again the value of the number to a integer. I have modified the properties from design like this:

[Image of designer]

and nothing happened, also in the Form.Load event I set this property programmatically but it seems that just don't work.

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

I have checked the DevExpress forums but I can't find an answer, it's my first question in here, so if any of you guys can help me I would really appreciate it.

Upvotes: 1

Views: 3111

Answers (2)

little m
little m

Reputation: 113

I fixed the "problem", the bug was that I was charging data from a View and all products records returned as 0

select 0 as data1, 0 as data2 from Table

But it seems that SQL returned the number as Integer and I couldn't be able to modificate the value in the XtraGrid even when it was declared as Decimal or Numeric in the DataTable and the XtraGrid.

I fixed it like this:

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

Thanks guys for answering and I hope someone else benefits from my mistakes.

Upvotes: 1

nempoBu4
nempoBu4

Reputation: 6621

You are using the wrong type of values in your underlying data source. The values in your nBase field must be one of the floating-point number type like Single, Double, Decimal etc.
Here is example:

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}"

Upvotes: 1

Related Questions