Formatting 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种选择: 使用格式化字符串填充网格中的“金额”列。我不喜欢这个选项,因为它会弄

我有一个Infrastics UltraWinGrid绑定到一个数据源,其中包含一个金额(十进制)和一个货币(字符串)。我需要显示金额和货币格式:

Data source:          Grid contents: 
Amount   Currency     Amount
12.34    EUR          EUR 12.34
22.33    USD          USD 22.33
我在考虑3种选择:

  • 使用格式化字符串填充网格中的“金额”列。我不喜欢这个选项,因为它会弄乱十进制值的排序
  • 在InitializeRow事件中的每个单元格(单元格,而不是列!)上设置一个编辑器。然而,我不知道哪位编辑合适——有什么想法吗
  • 在InitializeLayout方法中格式化Amount列(列级别!)某种程度上取决于Currency列(Currency列作为隐藏列存在于网格中)-但我不知道这是否可行-有人知道如何设置吗? 或者还有其他建议吗
    我使用选项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);
    }