Formatting Infrastics ultrawingrid单元级格式化
我有一个Infrastics UltraWinGrid绑定到一个数据源,其中包含一个金额(十进制)和一个货币(字符串)。我需要显示金额和货币格式:Formatting Infrastics ultrawingrid单元级格式化,formatting,ultrawingrid,Formatting,Ultrawingrid,我有一个Infrastics UltraWinGrid绑定到一个数据源,其中包含一个金额(十进制)和一个货币(字符串)。我需要显示金额和货币格式: Data source: Grid contents: Amount Currency Amount 12.34 EUR EUR 12.34 22.33 USD USD 22.33 我在考虑3种选择: 使用格式化字符串填充网格中的“金额”列。我不喜欢这个选项,因为它会弄
Data source: Grid contents:
Amount Currency Amount
12.34 EUR EUR 12.34
22.33 USD USD 22.33
我在考虑3种选择:
我使用选项2,使用
编辑器和文本来完成。我在一行中有两列-十进制值
列和字符串格式字符串
列。下面是我在Value
列中设置独立格式的步骤
grid.InitializeRow += (sender, e) =>
{
DefaultEditorOwnerSettings settings = new DefaultEditorOwnerSettings();
settings.DataType = typeof(Decimal);
settings.Format = (string)e.Row.Cells["FormatString"].Value;
EditorWithText editor = new EditorWithText(new DefaultEditorOwner(settings));
e.Row.Cells["Value"].Editor = editor;
}
斯奎尔曼的回答很有效
不幸的是,代码为每一行创建了一个EditorWithText实例
这就是为什么我添加了以下内容:
Dictionary<string, EditorWithText> dic = new Dictionary<string, EditorWithText>();
EditorWithText getEditor(string format)
{
EditorWithText ed;
if (!dic.TryGetValue(format, out ed))
{
ed = new EditorWithText(
new DefaultEditorOwner(
new DefaultEditorOwnerSettings { Format = format }));
dic.Add(format, ed);
}
return ed;
}
grid.InitializeRow += (sender, e) =>
{
e.Row.Cells["Value"].Editor = getEditor((string)e.Row.Cells["FormatString"].Value);
}