文章分類/Infragistics
如果要更改每個單元格的掩碼或顯示格式,請為每個單元格創建一個編輯器實例並在那裡單獨指定它們。
private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) { // 1行目 if(e.Row.Index == 0) { DefaultEditorOwnerSettings settings = new DefaultEditorOwnerSettings(); settings.MaskInput = "#.000"; settings.Format = "N3"; DefaultEditorOwner owner = new DefaultEditorOwner(settings); EditorWithMask editor = new EditorWithMask(owner); e.Row.Cells["Col1"].Editor = editor; } // 2行目 else if(e.Row.Index == 1) { DefaultEditorOwnerSettings settings = new DefaultEditorOwnerSettings(); settings.MaskInput = "#.0000"; settings.Format = "N4"; DefaultEditorOwner owner = new DefaultEditorOwner(settings); EditorWithMask editor = new EditorWithMask(owner); e.Row.Cells["Col1"].Editor = editor; } }
結果
Tips
請注意,在無條件創建新編輯器實例並將其分配給單元格的算法的情況下,編輯器實例的數量隨著屏幕上顯示的單元格數量的增加而增加。另外,InitializeRow 事件的調用非常頻繁,例如滾動時,因此每次都會生成一個實例。
生成的編輯器不應無條件賦值,而應保存在某個變量中(字典、列表、數組或任何易於使用的變量),並使用可重用的算法,建議組合。