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
550
Grid's built-in tooltip is excessive in merged columns
posted

Hi,

when the mouse pointer hovers over a merged column, where the same content spans over several rows,  the grid's built-in tooltip gets the same size as the merged area. This can be quite excessive! Is it possible to limit the size of the tooltip to 1 line, which is enough to show the column's content.

Thanks for your help!

Parents
  • 469350
    Offline posted

    Hi Manni,

        The grid tooltips are the same size as the cell. I understand that something this can look a little odd in a merged cell case where the text is small. But the grid can't really make any intelligent judgements about when this looks good and when it doesn't.

        You can alter this behavior using a CreationFilter.

        Here's a sample CreationFilter that displays normal tooltips on Merged Cells. You just copy this code and set the grid's CreationFilter property to an instance of the MergedCellToolTipCreationFilter class. 

        #region MergedCellToolTipCreationFilter
        public class MergedCellToolTipCreationFilter : IUIElementCreationFilter
        {
            #region IUIElementCreationFilter Members

            void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent)
            {
                // Watched for MergedCellUIElements
                if (parent is MergedCellUIElement)
                {
                    // See if it has a tooltip item and that it is not already a custom
                    // MergeCellToolTipItem
                    if (parent.ToolTipItem != null &&
                        (parent.ToolTipItem is MergeCellToolTipItem) == false)
                    {
                        // Replace the existing TooltipItem with a custom MergeCellToolTipItem
                        parent.ToolTipItem = new MergeCellToolTipItem(parent.ToolTipItem);
                    }
                }
            }

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

            #endregion
        }
        #endregion //MergedCellToolTipCreationFilter

        #region MergeCellToolTipItem
        public class MergeCellToolTipItem : IToolTipItem
        {
            private IToolTipItem baseToolTipItem;

            public MergeCellToolTipItem(IToolTipItem baseToolTipItem)
            {
                this.baseToolTipItem = baseToolTipItem;
            }

            #region IToolTipItem Members

            public ToolTipInfo GetToolTipInfo(Point mousePosition, UIElement element, UIElement previousToolTipElement, ToolTipInfo toolTipInfoDefault)
            {
                // Create a new ToolTipInfo based on the values passed in.
                ToolTipInfo newToolTipInfo = baseToolTipItem.GetToolTipInfo(mousePosition, element, previousToolTipElement, toolTipInfoDefault);           

                // Set the location to the location of the mouse.
                newToolTipInfo.Location = mousePosition;

                // Set the size to empty so the tooltip will automatically calculate the size based on the
                // contents.
                newToolTipInfo.Size = Size.Empty;

                // Exclude a rect where the mouse point is.
                Rectangle rect = new Rectangle(mousePosition, new Size(0,20));           
                newToolTipInfo.ExclusionRect = rect;

                // Return the new tooltip info.
                return newToolTipInfo;
            }

            #endregion
        }
        #endregion //MergeCellToolTipItem

Reply Children