【发布时间】:2009-07-22 13:38:57
【问题描述】:
我正在努力使用 WinForms DataGridView。我有一个类,我将其用作要显示的元素:
public class BorderFlowHistoryElement
{
public string nodeTitles { get; set; }
public double borderFlowRatio { get; set; }
...
}
我创建了这些元素的列表:
List<BorderFlowHistoryElement> clusterHistory
其中包含应显示在我的 DataGridView 中的 thise 元素列表。我在 Grid 的 DataSource 处绑定了列表:
dataGridViewCluster.DataSource = clusterHistory;
现在 DataGridView 显示列表。现在我想将显示双精度值的列格式化为显示 5 位数字。我试过了:
dataGridViewCluster.Columns[1].DefaultCellStyle.Format = "n5";
但这对列没有影响。任何人都知道,我该怎么做? 此外,我想调整列宽以最适合最大条目。
提前致谢, 弗兰克
【问题讨论】:
-
您是在寻找总位数还是精度?您正在指定精度,因此如果您有一个数字 1234 并且您使用 N5,您将得到 1,234.00000。这就是你想要的吗?
-
我正在寻找精度。例如 3.1415672467234823499821 应该变成 3.14157