简体   繁体   中英

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

I have a list of countries to be displayed inside the table layout panel(one col x many rows). A combobox filter exists to filter the different continents and based on the filtered continent name, the list of countries are made visible and hidden inside the table view. However, when you scroll the scroller up and down and then you apply a combo-box filter to a different continent name, the scroller doesn't scroll up to the top. The scroller should return to the first visible country control/component inside the table panel layout.

Has anyone has experienced this issue before. The code looks something like this. Any help will be much appreciated. I have been trying different options, nothing seems to have any effect on the scroller.

<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.

If that's exactly what you need, then the following should do the job

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM