2016-04-01 30 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中聲明瞭。 –

相關問題