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
1440
How to keep Column Group Header Caption always visible on screen
posted

Hi, I have a question about the group caption in WinGrid.

The caption in group column header can only be aligned to the left of the group.  When users are scrolling horizontally, the caption can't be show on the screen.  Is there anyway to keep the caption floating?

Please see attached screenshot.  On the second image, the caption 'AGLPA' is lost.

Thanks.

 

Regards,

Jason

Parents
  • 469350
    Offline posted

    Hi Jason,

    If you want to keep the group header in view at all times, then you'd have to use a CreationFilter. There's no property setting for this.

    If you have not worked with CreationFilters before, they can be a bit daunting, but they are well worth the effort they take to learn because they are so powerful.

    This one is a bit tricky. What you have to do is make sure the TextUIElement that is inside the HeaderUIElement for the group doesn't span the entire width of the HeaderUIElement (which gets scrolled off-screen), but is instead limited by the visible area of the grid. And you would have to do this for both the left and the right.

    And just to make this even more complicated, you would have to refresh the elements any time the grid scrolls.

    Here's some quick sample code I whipped up which seems to work okay, although I didn't test it very thoroughly:


        public class MyCreationFilter : IUIElementCreationFilter
        {
            #region IUIElementCreationFilter Members

            void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent)
            {
                HeaderUIElement headerUIElement = parent as HeaderUIElement;

                if (headerUIElement != null &&
                    headerUIElement.Header != null &&
                    headerUIElement.Header.Group != null)
                {
                    UIElement textUIElement = parent.GetDescendant(typeof(TextUIElement));
                    UIElement rowColRegionIntersectionUIElement = parent.GetAncestor(typeof(RowColRegionIntersectionUIElement));
                    if (textUIElement != null &&
                        rowColRegionIntersectionUIElement != null)
                    {
                        int newLeft = rowColRegionIntersectionUIElement.Rect.Left;
                        if (newLeft > textUIElement.Rect.Left)
                        {
                            int newWidth = textUIElement.Rect.Width - (newLeft - textUIElement.Rect.Left);
                            textUIElement.Rect = new Rectangle(
                                newLeft,
                                textUIElement.Rect.Top,
                                newWidth,
                                textUIElement.Rect.Height);

                            textUIElement.Invalidate();
                        }
                        else
                        {
                            int newRight = rowColRegionIntersectionUIElement.Rect.Right;
                            if (newRight < textUIElement.Rect.Right)
                            {
                                int newWidth = textUIElement.Rect.Width - (textUIElement.Rect.Right - newRight);
                                textUIElement.Rect = new Rectangle(
                                    textUIElement.Rect.Left,
                                    textUIElement.Rect.Top,
                                    newWidth,
                                    textUIElement.Rect.Height);

                                textUIElement.Invalidate();
                            }
                        }
                    }
                }
            }

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

            #endregion
        }

     

Reply Children