更改DataGridView的数字列中的数字组分隔符 [英] Change number group separator in numeric columns of DataGridView

查看:100
本文介绍了更改DataGridView的数字列中的数字组分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以这种方式格式化数字单元格 1,231 241.45 。我已经尝试过 N2 格式选项:

I want to format cells that are numeric in this way 1 231 241.45. I've tried N2 format option:

datagridview1.Columns["col1"].DefaultCellStyle.Format = "N2";

但是 N2 格式使用逗号代替空格。我想要空格作为数字组分隔符。
是否可以更改数字组分隔符?

But N2 format puts comma instead of space. I want space as number group separator. Is it possible to change number group separator?

推荐答案

要更改 DataGridView 中的数字组分隔符,您可以创建一个特定区域性,然后将其 NumberFormat.NumberGroupSeparator 设置为新值,然后设置<$ c $的 DefaultCellStyle.FormatProvider c> DataGridView 到修改后的区域性:

To change the number group separator in DataGridView you can create a specific culture and then set its NumberFormat.NumberGroupSeparator to new value, then set DefaultCellStyle.FormatProvider of the DataGridView to the modified culture:

var culture = CultureInfo.CreateSpecificCulture("en-GB");
culture.NumberFormat.NumberGroupSeparator = " ";
dataGridView1.DefaultCellStyle.FormatProvider = culture;
dataGridView1.Columns[1].DefaultCellStyle.Format = "N2";

这篇关于更改DataGridView的数字列中的数字组分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆