Windows 使用 combofilterbox 时,Form C# tablelayoutpanel 向上滚动到顶部不更新

Windows Form C# tablelayoutpanel scroll up to the top not updating when combofilterbox is used

我有一个国家列表要显示在 table 布局面板中(一列 x 多行)。存在一个组合框过滤器来过滤不同的大陆,并根据过滤后的大陆名称,使国家/地区列表可见并隐藏在 table 视图中。但是,当您上下滚动滚动条然后将组合框过滤器应用于不同的大陆名称时,滚动条不会向上滚动到顶部。滚动条应 return 到 table 面板布局内的第一个可见国家 control/component。

有没有人以前遇到过这个问题。代码看起来像这样。任何帮助都感激不尽。我一直在尝试不同的选项,似乎对滚动条没有任何影响。

<pre>
{
....
 if (scrollDirection == ScrollDirection.Up)
            {
                Control usercontrol = GetFirstVisibleCountryUC();
                if (usercontrol != null)
                {
                    tableLayoutPanelCountries.ScrollControlIntoView(usercontrol);
                    tableLayoutPanelCountries.Invalidate(); //Refresh, Update have tried different options
                }
            }
.....
}
 private Control GetFirstVisibleCountryUC()
        {
            foreach (CountryUC uc in this.tableLayoutPanelCountries.Controls)
            {
                if (uc.Visible)
                {
                    return uc;
                }
            }
            return null;           
        }
</pre>

The scroller should return to the first visible country control/component inside the table panel layout.

如果这正是您所需要的,那么下面的内容应该可以完成工作

tableLayoutPanelCountries.AutoScrollPosition = new Point(0, 0);