簡體   English   中英

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字段中的值必須是浮點數類型之一,例如SingleDoubleDecimal等。
這是示例:

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

我修復了“問題”,錯誤是我從View收取數據,所有產品記錄都返回0

select 0 as data1, 0 as data2 from Table

但是似乎SQL返回的數字為Integer,即使在DataTable和XtraGrid中將其聲明為Decimal或Numeric,我也無法修改XtraGrid中的值。

我這樣修復:

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

謝謝大家的回答,我希望其他人也可以從我的錯誤中受益。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM