This is a migrated thread and some comments may be shown as answers.

VisualItemFormatting tooltips

1 Answer 181 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 21 May 2012, 01:56 AM
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

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 23 May 2012, 02:50 PM
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 >>
Tags
GridView
Asked by
Matthew
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or