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
130
Limiting scrollbars when using fixed headers
posted

Is there anyway to limit the horizontal scroll bar so that is does not extend beneath any fixed columns on the left hand side?

I was showing a prototype to some customers recently. They were confused by the scroll bars extending all the way across the width of grid when not all of the columns are affected by scrolling. The "fixed" buttons are hidden so users will not be able to change the set of fixed columns.

As a work around, I could use 2 different tables, one for the fixed columns and one for the rest. That adds complexity since I would have to sync the vertical scrolling.

I am using V8.3

  • 469350
    Suggested Answer
    Offline posted

    There's no built-in way to do this. You might be able to do it using a CreationFilter. But it would be a bit tricky, because you would have to determine the right-most edge of the last fixed column every time. 

    I whipped up some code that seems to work okay, but it might not be terribly efficient.


        public class FixedHeaderScrollBar_CreationFilter : IUIElementCreationFilter
        {       
            #region IUIElementCreationFilter Members

            void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent)
            {
                // Check for a ColScrollbarUIElement
                if (parent is ColScrollbarUIElement)
                {
                    // Get the grid control.
                    UltraGrid grid = parent.Control as UltraGrid;

                    // See if we are using FixedHeader
                    if (grid.DisplayLayout.UseFixedHeaders)
                    {
                        // Find the right-most fixed header
                        UltraGridColumn rightMostFixedColumn = null;
                        int rightMostFixedColumnVisiblePosition = -1;
                        foreach (UltraGridColumn column in grid.DisplayLayout.Bands[0].Columns)
                        {
                            if (column.Header.Fixed)
                            {
                                if (column.Header.VisiblePosition > rightMostFixedColumnVisiblePosition)
                                {
                                    rightMostFixedColumnVisiblePosition = column.Header.VisiblePosition;
                                    rightMostFixedColumn = column;
                                }
                            }
                        }

                        // If we found no fixed header, bail out.
                        if (rightMostFixedColumn == null)
                            return;

                        // Get the HeaderUIElement of the last fixed column.
                        HeaderUIElement headerElement = parent.Parent.Parent.GetDescendant(typeof(HeaderUIElement), rightMostFixedColumn) as HeaderUIElement;
                        if (headerElement == null)                       
                            return;

                        // Set the rect of the ColScrollbarUIElement so that it aligns to the right of the
                        // last fixed column.
                        parent.Rect = new Rectangle(
                            headerElement.Rect.Right,
                            parent.Rect.Top,
                            parent.Parent.Rect.Width - headerElement.Rect.Right,
                            parent.Rect.Height
                            );
                    }
                }
            }

            bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent)
            {
                // Do nothing.
                return false;
            }

            #endregion
        }