From 75504b6870a8e183b43ca591e1f24bbaa9a08f2a Mon Sep 17 00:00:00 2001 From: "GukSang.Jin" Date: Mon, 5 Jan 2026 18:31:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WindowsFormsApp6/Form1.cs | 14 ++++++++------ WindowsFormsApp6/Form2.cs | 31 +++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/WindowsFormsApp6/Form1.cs b/WindowsFormsApp6/Form1.cs index 4f12493..5d599ee 100644 --- a/WindowsFormsApp6/Form1.cs +++ b/WindowsFormsApp6/Form1.cs @@ -459,12 +459,14 @@ namespace WindowsFormsApp6 double avg1 = count1 > 0 ? sum1 / count1 : 0; - // 添加试样1-5平均值行 + // 添加试样1-5平均值行 - 只在第一列显示平均值 DataRow avgRow1 = sampleDataTable.NewRow(); avgRow1["序号"] = "平均时间(s)试样1-5"; + + // 只在试样1列显示平均值 avgRow1["试样1"] = avg1; - // 其他列设置为空 + // 其他列设置为DBNull(不显示) for (int i = 2; i <= currentSampleCount; i++) { avgRow1[$"试样{i}"] = DBNull.Value; @@ -491,20 +493,20 @@ namespace WindowsFormsApp6 double avg2 = count2 > 0 ? sum2 / count2 : 0; - // 添加试样6-10平均值行 + // 添加试样6-10平均值行 - 只在第6列显示平均值 DataRow avgRow2 = sampleDataTable.NewRow(); avgRow2["序号"] = "平均时间(s)试样6-10"; - // 前5列为空 + // 前5列为DBNull(不显示) for (int i = 1; i <= 5; i++) { avgRow2[$"试样{i}"] = DBNull.Value; } - // 第6列显示平均值 + // 只在试样6列显示平均值 avgRow2["试样6"] = avg2; - // 其他列为空 + // 其他列为DBNull(不显示) for (int i = 7; i <= currentSampleCount; i++) { avgRow2[$"试样{i}"] = DBNull.Value; diff --git a/WindowsFormsApp6/Form2.cs b/WindowsFormsApp6/Form2.cs index 085aad7..63fd3a3 100644 --- a/WindowsFormsApp6/Form2.cs +++ b/WindowsFormsApp6/Form2.cs @@ -465,8 +465,15 @@ namespace WindowsFormsApp6 avgRow1["试样1"] = avgAbsorption1; } - // 其他列为空 - for (int i = 2; i <= count; i++) + // 试样2-5列为空(只设置到第5列或count,取较小值) + int maxCol1 = Math.Min(5, count); + for (int i = 2; i <= maxCol1; i++) + { + avgRow1[$"试样{i}"] = DBNull.Value; + } + + // 如果有试样6-10,这些列也设置为空 + for (int i = 6; i <= count; i++) { avgRow1[$"试样{i}"] = DBNull.Value; } @@ -509,8 +516,14 @@ namespace WindowsFormsApp6 maxRow1["试样1"] = maxAbsorption1; } - // 其他列为空 - for (int i = 2; i <= count; i++) + // 试样2-5列为空 + for (int i = 2; i <= maxCol1; i++) + { + maxRow1[$"试样{i}"] = DBNull.Value; + } + + // 如果有试样6-10,这些列也设置为空 + for (int i = 6; i <= count; i++) { maxRow1[$"试样{i}"] = DBNull.Value; } @@ -553,8 +566,14 @@ namespace WindowsFormsApp6 stdDevRow1["试样1"] = stdDev1; } - // 其他列为空 - for (int i = 2; i <= count; i++) + // 试样2-5列为空 + for (int i = 2; i <= maxCol1; i++) + { + stdDevRow1[$"试样{i}"] = DBNull.Value; + } + + // 如果有试样6-10,这些列也设置为空 + for (int i = 6; i <= count; i++) { stdDevRow1[$"试样{i}"] = DBNull.Value; }