VisualItemFormatting tooltips

2 posts, 0 answers
  1. Matthew
    Matthew avatar
    16 posts
    Member since:
    Oct 2010

    Posted 20 May 2012 Link to this post

    Hi There,

    I'm working on a grid which has a GridViewComboBoxColumn. the column is often not wide enough the fit the item text. So i wanted to add a tool tip for each item in the list.
    I found this article which seemed to be what i was after:
    http://www.telerik.com/community/forums/winforms/dropdownlist-and-listcontrol/auto-horizontal-scroll-and-item-tooltip-in-radlistcontrol.aspx

    but my code doesn't seem to work:

    protected void rgDraft_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        if (e.Column.Name == "Country")
        {
            RadDropDownListEditor editor = (RadDropDownListEditor)this.rgDraft.ActiveEditor;
            RadDropDownListEditorElement editorElement = (RadDropDownListEditorElement)editor.EditorElement;
                         
            editorElement.VisualItemFormatting += new VisualListItemFormattingEventHandler(delegate(object formattingsender, VisualItemFormattingEventArgs args)
                {
                    args.VisualItem.ToolTipText = args.VisualItem.Text;
                });
        }
    }

    Any idea why this doesn't work? I can do other things, like set the bgcolor to red and that works as expected

    Many thanks,
    Matt
  2. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 23 May 2012 Link to this post

    Hi Matthew,

    Thank you for writing.

    We are aware of this limitation and it is already logged in PITS. Here is a link where you can add your vote for it: http://www.telerik.com/support/pits.aspx#/public/winforms/7712.

    Meanwhile, you can show the tooltips, by using the following code:
    void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        if (e.Column.Name == "combo")
        {
            RadDropDownListEditor editor = (RadDropDownListEditor)e.ActiveEditor;
            RadDropDownListEditorElement editorElement = (RadDropDownListEditorElement)editor.EditorElement;
     
            editorElement.Popup.ToolTipTextNeeded -= new Telerik.WinControls.ToolTipTextNeededEventHandler(Popup_ToolTipTextNeeded);
            editorElement.Popup.ToolTipTextNeeded += new Telerik.WinControls.ToolTipTextNeededEventHandler(Popup_ToolTipTextNeeded);
        }
    }
     
    ToolTip tip = new ToolTip();
    void Popup_ToolTipTextNeeded(object sender, Telerik.WinControls.ToolTipTextNeededEventArgs e)
    {
        RadListVisualItem item = sender as RadListVisualItem;
     
        if (item != null)
        {
            AssignTooltips(item);
            tip.Show(item.ToolTipText, this, this.PointToClient(Cursor.Position));
        }
    }
     
    private void AssignTooltips(RadListVisualItem item)
    {
        if (item.AutoEllipsis = true && TextRenderer.MeasureText(item.Text, item.Font).Width > item.Size.Width)
        {
            item.ToolTipText = item.Text;
        }
        else
        {
            item.ToolTipText = "";
        }
    }

    I hope this helps. Let us know if you have any other questions.

    Greetings,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top