From 2798c6d59a270708da7736bbefc9613e39d1e276 Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 12 Jul 2023 10:01:33 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIDataGridView:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=86=E6=9C=89=E5=86=BB=E7=BB=93=E8=A1=8C=E6=97=B6=E5=9E=82?= =?UTF-8?q?=E7=9B=B4=E6=BB=9A=E5=8A=A8=E6=9D=A1=E7=82=B9=E5=87=BB=E6=97=B6?= =?UTF-8?q?=E5=87=BA=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UIDataGridView.cs | 40 ++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/SunnyUI/Controls/UIDataGridView.cs b/SunnyUI/Controls/UIDataGridView.cs index df1dccc8..28a09709 100644 --- a/SunnyUI/Controls/UIDataGridView.cs +++ b/SunnyUI/Controls/UIDataGridView.cs @@ -45,6 +45,7 @@ * 2022-07-28: V3.2.2 修复了单行时表格高度低时,垂直滚动条拖拽至底部出错的问题 * 2022-10-14: V3.2.6 增加了可设置垂直滚动条宽度的属性 * 2023-06-28: V3.3.9 增加了可设置水平滚动条宽度的属性,但可能会遮挡最下面数据行的数据,看情况使用 + * 2023-07-12: V3.4.0 修复了有冻结行时垂直滚动条点击时出错的问题 ******************************************************************************/ using System; @@ -369,6 +370,23 @@ namespace Sunny.UI if (idx < 0) idx = 0; if (idx >= RowCount) idx = RowCount - 1; + int lastFrozen = GetFrozenBottomIndex(); + if (Rows[0].Frozen) + { + if (RowCount > lastFrozen + 1) + { + lastFrozen += 1; + FirstDisplayedScrollingRowIndex = Math.Max(idx, lastFrozen); + } + } + else + { + FirstDisplayedScrollingRowIndex = idx; + } + } + + private int GetFrozenBottomIndex() + { int lastFrozen = 0; if (Rows[0].Frozen) { @@ -385,12 +403,7 @@ namespace Sunny.UI } } - if (Rows[0].Frozen) - { - - } - - FirstDisplayedScrollingRowIndex = Math.Max(idx, lastFrozen); + return lastFrozen; } private void HorizontalScrollBar_ValueChanged(object sender, EventArgs e) @@ -753,7 +766,20 @@ namespace Sunny.UI } Rows[value].Selected = true; - FirstDisplayedScrollingRowIndex = value; + + int lastFrozen = GetFrozenBottomIndex(); + if (Rows[0].Frozen) + { + if (RowCount > lastFrozen + 1) + { + lastFrozen += 1; + FirstDisplayedScrollingRowIndex = Math.Max(value, lastFrozen); + } + } + else + { + FirstDisplayedScrollingRowIndex = value; + } if (selectedIndex >= 0 && selectedIndex <= Rows.Count) jumpIndex = selectedIndex;