2013-03-26 41 views
1

我想以這種方式格式化數值單元「1 231 241.45」。 N2格式選項正在格式化單元格,但它將逗號而不是空格。我想在那裏空間。有可能的?Datagrid defaultcellstyle.format numeric WinForms

+0

_IT是可能的嗎?_你有沒有嘗試過什麼嗎?顯示你的努力!請閱讀[常見問題]和[問] – 2013-03-26 09:12:16

+0

感謝您的回答。這對我很有幫助!我想我必須使用format.ToString(「」),但不知道要放在裏面... – 2013-03-26 09:14:25

+2

真的嗎? =)順便說一句,這不是一個答案!這是[*評論*](http://stackoverflow.com/privileges/comment)。 – 2013-03-26 09:16:29

回答

3

我設法使其與下面的代碼工作:

string NRFormat="### ### ##0.00" 
datagridview1.Columns["col1"].DefaultCellStyle.Format = NRFormat; 
datagridview1.Columns["col2"].DefaultCellStyle.Format = NRFormat; 

這不是很優雅,但它的工作。

0

你可以試試這個。

//1000001 convert to 1 000 001.00 
datagridview1.Columns["col1"].DefaultCellStyle.Format = "### ### ##0.00"; 

//1000 convert to 1 000.00 
datagridview1.Columns["col2"].DefaultCellStyle.Format = "### ### ##0.00"; 
0

在數據網格單元格格事件做以下

私人無效dg_CellFormatting(對象發件人,DataGridViewCellFormattingEventArgs E) {

 if (cell.Value is decimal) 
     { 
      e.CellStyle.Format = "0.##"; 
     } 
    }