列格式为代码后面的货币

时间:2014-03-21 20:20:44

标签: c# wpf datagrid

我想设置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。

2 个答案:

答案 0 :(得分:0)

检查列上是否存在绑定属性。如果这样设置它的String.Format。我没有使用过Extended Datagrid,但是这个解决方案在我以前的其他C#WPF网格中已经有用了。

答案 1 :(得分:0)

知道了,这就是我做的方式:

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

感谢@Vulcronos