Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
470
Scrollbar exists only temporarily
posted

I have a grid that I need to know if the row scrollbar is showing. I am using code that shows this effectively in most cases, but for some reason in some cases the grid is telling me there is a scrollbar, so this is giving me serious problems.

Here is my code for checking to see if there is a scrollbar:

       public static bool HasVerticalScrollBarVisible(UltraGrid ug)
        {
            RowColRegionIntersectionUIElement uiCSR = ug.DisplayLayout.ColScrollRegions[0].GetUIElement(ug.DisplayLayout.RowScrollRegions[0]);//ug.ActiveColScrollRegion.GetUIElement(ug.ActiveRowScrollRegion);

            /*
            object o = uiCSR.Parent.GetDescendant(typeof(ColScrollbarUIElement));
            ColScrollbarUIElement uiCScrollbar = o as ColScrollbarUIElement;
            if (null != uiCScrollbar)
            {
                r += 1;
            }*/
            object o = uiCSR.Parent.GetDescendant(typeof(RowScrollbarUIElement));
            RowScrollbarUIElement uiRScrollbar = o as RowScrollbarUIElement;

            if (uiRScrollbar == null)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

As I said, it works fine in most cases. Where it doesn't work is when it is called several times in the course of a form loading. The last time it is called, it returns true. For some reason the code is findng a UI element of type RowScrollbarUIElement!!!

  • 469350
    Offline posted

    Hi,

    UIElements are created when the grid paints. So as you can imagine, they get created and destroyed quite often and there might be a scrollbar one second and then no scrollbar the next as the grid processes it's elements.

    To ensure that the grid is up-to-date, try putting a call to grid.Refresh at the top of this method. That will force the grid to paint and any pending UIElement updates should get resolved at that point.

    If that doesn't work, you could also try calling grid.DisplayLayout.UIElement.DirtyChildElements(true) before the Refresh and see if that helps.