From b1c3e2781b3c6451e3f848df38578a47a71e24cc Mon Sep 17 00:00:00 2001 From: "GukSang.Jin" Date: Tue, 6 Jan 2026 11:33:44 +0800 Subject: [PATCH] gx --- WindowsFormsApp6/Form3.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/WindowsFormsApp6/Form3.cs b/WindowsFormsApp6/Form3.cs index d5d4e42..8e0b49f 100644 --- a/WindowsFormsApp6/Form3.cs +++ b/WindowsFormsApp6/Form3.cs @@ -254,12 +254,31 @@ namespace WindowsFormsApp6 { if (e.RowIndex < 0 || e.ColumnIndex == 0) return; // 跳过序号列 + // 获取当前行的序号,判断是否是标准偏差行 + string rowName = ""; + if (e.RowIndex < dataGridView1.Rows.Count) + { + var row = dataGridView1.Rows[e.RowIndex]; + if (row.Cells["序号"].Value != null) + { + rowName = row.Cells["序号"].Value.ToString(); + } + } + // 格式化数值显示为2位小数 if (e.Value != null && e.Value != DBNull.Value) { if (double.TryParse(e.Value.ToString(), out double numValue)) { - // 如果值为0或接近0,显示为空白 + // 标准偏差行:即使为0也要显示 + if (rowName == ROW_STD_DEVIATION) + { + e.Value = numValue.ToString("F2"); + e.FormattingApplied = true; + return; + } + + // 其他行:如果值为0或接近0,显示为空白 if (Math.Abs(numValue) < 0.001) { e.Value = "";