【问题标题】:Column format to currency in code behind代码后面的列格式为货币
【发布时间】:2014-03-21 20:20:44
【问题描述】:

我想将我必须的 p&l 列设置为货币,当我绑定它时效果很好,很容易在 XAML 中设置,但我有不使用绑定的内部数据网格,所以我需要将其格式更改为货币在后面的代码中。我该怎么做,这是我目前所拥有的:

private void dataGrid_RowDetailsVisibilityChanged(object sender, ExtendedGrid.Microsoft.Windows.Controls.DataGridRowDetailsEventArgs e)
{

        //Get TradeID  to query inner table by that trade id
        var row = e.Row;
        var drv = (DataRowView)row.DataContext;
        int TradeID = drv.Row.Field<int>(ColTradeID);

        ExtendedGrid.Microsoft.Windows.Controls.DataGrid innerDataGrid = e.DetailsElement as ExtendedGrid.Microsoft.Windows.Controls.DataGrid;

        DataTable TableView = null;

        //check if tradeid selected already exists
        if (selectedRowView.ContainsKey(TradeID))
        {
            TableView = selectedRowView[TradeID]; //selectedrowview is a dictionary of datatables that stores what to load in itemsource based on a tradeId
            innerDataGrid.ItemsSource = ((IListSource)selectedRowView[TradeID]).GetList();

            //Format Columns
            innerDataGrid.Columns[10].CellStyle = "C"; // **I want currency, this doesn't work, 
                                                      //I also tried typing defaultcelltype.format and nothing would come up its not available for use**
        }           
}

另外,我使用的是 WPF 扩展数据网格,而不是 WPF 内置的。

【问题讨论】:

    标签: c# wpf datagrid


    【解决方案1】:

    检查列上是否有绑定属性。如果是这样设置它的 String.Format。我没有使用过扩展数据网格,但这个解决方案过去曾在其他 C# WPF 网格上为我工作过。

    【讨论】:

    • 我该如何检查? @Vulcronos
    【解决方案2】:

    知道了,我是这样做的:

    innerDataGrid.Columns[10].ClipboardContentBinding.StringFormat = "$00.00";
    

    感谢@Vulcronos

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      • 2014-01-17
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      相关资源
      最近更新 更多