2016-11-03 68 views
1

如何在Eto中創建數字列(理想情況下爲整數)形成GridView?數字Eto Grid單元格?

下面是我的兩個字符串列

stats.Columns.Add(new GridColumn 
{ 
    DataCell = new TextBoxCell { Binding = Binding.Property<RulesDocAdapter, string>(r => r.Name) }, 
    HeaderText = "Name" 
}); 

stats.Columns.Add(new GridColumn 
{ 
    DataCell = new TextBoxCell { Binding = Binding.Property<RulesDocAdapter, string>(r => r.Abbreviation) }, 
    HeaderText = "Abbreviation" 
}); 

回答

1

代碼要使用不同的列,您可以使用轉換()擴展的屬性綁定的整數屬性轉換爲字符串,像這樣:

Binding.Property((RulesDocAdapter r) => r.IntProperty).Convert(v => v.ToString(), s => { int i = 0; return int.TryParse(s, out i) ? i : -1; }) 
+0

謝謝!該代碼是一種模糊,所以我有麻煩工作,這個魔術out1 –

+0

這適用於顯示,但更新失敗。我認爲它有一個轉換異常,這會讓人窒息。 如果我想int屬性是可編輯的,我需要做什麼? –

+0

當前代碼: 'stats.Columns.Add(新的GridColumn { DATACELL =新TextBoxCell {結合= Binding.Property((RulesDocAdapter R)=> r.Cost).Convert(V => v.ToString( ))}, HeaderText =「Cost」, Editable = true }); ' –