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
4028
Column Header Captions - displaying overflow when not overflowing
posted

Here is my situation. I have a number of columns in my application which have very long winded names. "Qty. Reserved From Order", "Qty. Reserved From Inventory", etc. This presents a bit of a problem when the user reduces the width these columns (which are side by side), so both of them read "Qty. Reser". If the user mouse overs the column it says the full column name in a little box that pops up. This is nice, but not quite handy enough for me.

What I'm planning on doing is writing code so that when the column is made too narrow, it will replace "Qty. Reserved From Order" with something like "Q-O". This is all fairly straight forward.

 The problem is, when I do this, it all changes the mouse over thing for the column header. When I mouse over the column header, it displays "Q-O" (assuming the column is too narrow), where I want this functionality to still display "Qty. Reserved From Order".

So my question is, is there a way of having the column header text as one thing, but the column header mouse over thing displaying another thing?

I have tried playing with the ToolTipText property (column.Header.ToolTipText), which kind of works, but it displays a in a different area as where the normal header mouseover text appears.

Thanks.

Parents
  • 37774
    Verified Answer
    posted

    I would think that the column's header overflow tooltip will get the name from the Caption of the header, so changing this so it's different in the grid itself will also affect the tooltip (as you're seeing in the application).  I think the best approach here would be to use a DrawFilter and draw the text yourself:

    private class DF : IUIElementDrawFilter
    {

        #region IUIElementDrawFilter Members

        public bool DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams)
        {
            TextUIElement textElem = (TextUIElement)drawParams.Element;
            HeaderUIElement headerElem = drawParams.Element.GetAncestor(typeof(HeaderUIElement)) as HeaderUIElement;
            if (headerElem != null)
            {
                // The TextSize property relies on the text having been rendered at least once, so if you need to
                // change the header caption when initially showing the grid, you need to measure the text yourself
                if (textElem.TextSize.Width > textElem.RectInsideBorders.Width)
                {
                    string caption = headerElem.Header.Caption;
                    string newCaption = "Blah"; // Change to whatever you need

                    drawParams.DrawString(textElem.RectInsideBorders, newCaption, false, false);
                    return true;
                }
            }

            return false;
        }

        public DrawPhase GetPhasesToFilter(ref UIElementDrawParams drawParams)
        {
            if (drawParams.Element is TextUIElement)
                return DrawPhase.BeforeDrawForeground;

            return DrawPhase.None;
        }

        #endregion
    }

    -Matt

Reply Children