我只是想知道是否有一种方法可以在 DataGridViewCellStyle 中创建自定义格式来显示数千个数据。
在 Excel 中有一种自定义格式,您可以在单元格中键入 1000,但它显示为 1。我尝试搜索这些板,但我所有的搜索都返回如何插入千个分隔符,我已经知道如何插入要做的事。
我当前的解决方法是在加载 DGV 之前将数据除以 1000,然后将返回的用户输入乘以 1000,但必须有更好的方法。我正在处理一些非常大的数字(以智利比索计算,不少于),所以我无法显示真实的数字。
最佳答案
使用格式字符串“0”
Number scaling specifier: If one or more ',' characters is specified immediately to the left of the explicit or implicit decimal point, the number to be formatted is divided by 1000 each time a number scaling specifier occurs
在 RichTextBox 中,这种格式对我有用:
richTextBox.Text = String.Format("{0:0,}", 24000);//Show as 24
在 DataGridView 中,可以在设计器中或通过代码使用相同的格式:
//Number format "0,.###" will show number 12230 as 12.23
this.datagridview.Columns[this.dgvYuorColumn.Name].DefaultCellStyle.Format = "0,.###";
关于DataGridViewCellStyle 显示以千为单位的数值数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15668897/