* UIDataGridView: 解决有隐藏行时,滚动条滚动时出错的问题 #IAOW3A

This commit is contained in:
Sunny 2024-09-04 21:33:52 +08:00
parent d1957cb75c
commit 7fb69265ee

View File

@ -49,6 +49,7 @@
* 2023-11-05: V3.5.2 * 2023-11-05: V3.5.2
* 2024-06-19: V3.6.7 AddDateTimeColumn * 2024-06-19: V3.6.7 AddDateTimeColumn
* 2024-08-27: V3.7.0 AutoScrollToBottom * 2024-08-27: V3.7.0 AutoScrollToBottom
* 2024-09-04: V3.7.0
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -386,18 +387,49 @@ namespace Sunny.UI
if (idx < 0) idx = 0; if (idx < 0) idx = 0;
if (idx >= RowCount) idx = RowCount - 1; if (idx >= RowCount) idx = RowCount - 1;
SetFirstDisplayedScrollingRowIndex(idx);
}
private void SetFirstDisplayedScrollingRowIndex(int idx)
{
int lastFrozen = GetFrozenBottomIndex(); int lastFrozen = GetFrozenBottomIndex();
int showidx = idx;
if (Rows[0].Frozen) if (Rows[0].Frozen)
{ {
if (RowCount > lastFrozen + 1) if (RowCount > lastFrozen + 1)
{ {
lastFrozen += 1; lastFrozen += 1;
FirstDisplayedScrollingRowIndex = Math.Max(idx, lastFrozen); showidx = Math.Max(idx, lastFrozen);
} }
} }
else
bool isSet = false;
for (int i = showidx; i < RowCount; i++)
{ {
FirstDisplayedScrollingRowIndex = idx; if (Rows[i].Visible)
{
showidx = i;
isSet = true;
break;
}
}
if (!isSet)
{
for (int i = showidx; i > 0; i--)
{
if (Rows[i].Visible && i > lastFrozen)
{
showidx = i;
isSet = true;
break;
}
}
}
if (isSet)
{
FirstDisplayedScrollingRowIndex = showidx;
} }
} }
@ -793,19 +825,7 @@ namespace Sunny.UI
Rows[value].Selected = true; Rows[value].Selected = true;
int lastFrozen = GetFrozenBottomIndex(); SetFirstDisplayedScrollingRowIndex(value);
if (Rows[0].Frozen)
{
if (RowCount > lastFrozen + 1)
{
lastFrozen += 1;
FirstDisplayedScrollingRowIndex = Math.Max(value, lastFrozen);
}
}
else
{
FirstDisplayedScrollingRowIndex = value;
}
if (selectedIndex >= 0 && selectedIndex <= Rows.Count) if (selectedIndex >= 0 && selectedIndex <= Rows.Count)
jumpIndex = selectedIndex; jumpIndex = selectedIndex;
@ -1057,7 +1077,7 @@ namespace Sunny.UI
//选中最后一行 //选中最后一行
this.Rows[this.RowCount - 1].Selected = true; this.Rows[this.RowCount - 1].Selected = true;
//滚动到最后一行 //滚动到最后一行
this.FirstDisplayedScrollingRowIndex = this.RowCount - 1; SetRowHeight(this.RowCount - 1);
//如果需要滚动到底部(右侧),使用下面的代码 //如果需要滚动到底部(右侧),使用下面的代码
//this.FirstDisplayedCell = this.Rows[this.RowCount - 1].Cells[this.Columns.Count - 1]; //this.FirstDisplayedCell = this.Rows[this.RowCount - 1].Cells[this.Columns.Count - 1];
} }