[英]Formatting datagridview cell to 2 decimal places
基本上我有一個數據網格視圖,它顯示數據表中的數據。 數據表中的每個單元格都是一個小數點,大約有 10 個小數點,如何使用 datagridview 將這些數據顯示到 2 個小數點?
我試過這個(我在其他問題中發現的):
for (int i = 0; i < this.dgvDynamics1.Columns.Count; i++)
this.dgvDynamics1.Columns[i].DefaultCellStyle.Format = "N2";
但它不起作用
如果您需要更多信息,請告訴我
提前致謝
嘗試這個:
this.dgvDynamics1.Columns.Items[i].DefaultCellStyle.Format = "0.00##";
this.dgvDynamics1.Columns.Items[i].ValueType = GetType(Double)
嘗試這個
private void dgvList_CellFormatting(object sender,DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 6 || e.ColumnIndex == 8)
{
e.CellStyle.Format = "N2";
}
}
這是一個舊帖子,但為了記錄,這應該有效:
for (int i = 0; i < this.dgvDynamics1.Columns.Count; i++)
this.dgvDynamics1.Columns[i].DefaultCellStyle.Format = "0.00";
就個人而言,我總是毫無問題地在設計器中更改格式這里的程序
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.