views:

504

answers:

1

i want to have a tooltip for each item in a treeview, and each item in a listview, and different for each subitem (i.e. column) in the listview.

i can determine the text i want to show (using hit testing with the current mouse position, etc):

private void toolTip1_Popup(object sender, PopupEventArgs e)
{
   if (e.AssociatedControl == listView1)
   {
      toolTip1.SetToolTip(listView1, "foo");
   }
}

but any attempt to set the tooltip text causes a stackoverflow.

How can i customize the tooltip (icon, title, text) just before it appears?

+1  A: 

You need to guard your code in the Popup event handler so that if you are calling SetToolTip from within it, you don't call SetToolTip again.

Something like:

private bool updatingTooltip;
private void toolTip1_Popup(object sender, PopupEventArgs e)
{   
    if (!this.updatingTooltip && (e.AssociatedControl == listView1))
    {
        this.updatingTooltip = true;
        toolTip1.SetToolTip(listView1, "foo");
        this.updatingTooltip = false;
    }
}
Jeff Yates