【问题标题】:How to set the decimal place of a DataGridTextColumn programmatically?如何以编程方式设置 DataGridTextColumn 的小数位?
【发布时间】:2016-11-05 00:17:38
【问题描述】:

我通过以下代码将列添加到 DataGrid:

dataGrid.Columns.Add(new DataGridTextColumn { Header = "n", Binding = new Binding("n") { StringFormat = "{0:n2}" } });

我绑定的数据是从数据库中检索到的 DataTable。 DataTable 中的值是数据库中的 money 类型,因此当在 DataGrid 中显示时,值将类似于 1000.0000。

StringFormat 设置为什么以删除小数位,因为 StringFormat = "{0:n2}" 不起作用。

【问题讨论】:

    标签: wpf datatable datagrid decimal


    【解决方案1】:

    使用这个: Binding = new Binding("n") { StringFormat = "{0,1:F4}" } });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-08
      相关资源
      最近更新 更多