简体   繁体   中英

How to set the decimal place of a DataGridTextColumn programmatically?

I am adding the columns to a DataGrid through the following code:

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

The data I am binding to is a DataTable retrieved from a database. The value in the DataTable is of type money in the database, thus when displayed in the DataGrid the values would be something like 1000.0000.

What is the StringFormat set to in order to remove the decimal places because StringFormat = "{0:n2}" does not work.

使用以下方法: Binding = new Binding("n") { StringFormat = "{0,1:F4}" } });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM