Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tooltips for CheckedListBox items?

Is there a straighforward way to set additional text to appear in a tooltip when a user's mouse is held over an item in a CheckedListBox?

What I would expect to be able to do in code is:

uiChkLstTables.DisplayOnHoverMember = "DisplayOnHoverProperty"; //Property contains extended details

Can anyone point me in the right direction to do this? I've already found a couple of articles that involve detecting which item the mouse is currently over and creating a new tooltip instance, but this sounds a little too contrived to be the best way.

Thanks in advance.

like image 486
Paul Suart Avatar asked Apr 29 '09 12:04

Paul Suart


2 Answers

Add a Tooltip object to your form and then add an event handler for the CheckedListBox.MouseHover that calls a method ShowToolTip(); Add MouseMove event of your CheckedListBox which has the following code:

//Make ttIndex a global integer variable to store index of item currently showing tooltip.
//Check if current location is different from item having tooltip, if so call method
if (ttIndex != checkedListBox1.IndexFromPoint(e.Location))
                ShowToolTip();

Then create the ShowToolTip method:

private void ShowToolTip()
    {
        ttIndex = checkedListBox1.IndexFromPoint(checkedListBox1.PointToClient(MousePosition));
        if (ttIndex > -1)
        {
            Point p = PointToClient(MousePosition);
            toolTip1.ToolTipTitle = "Tooltip Title";
            toolTip1.SetToolTip(checkedListBox1, checkedListBox1.Items[ttIndex].ToString());

        }
    }
like image 132
Fermin Avatar answered Oct 04 '22 03:10

Fermin


Alternately, you could use a ListView with checkboxes instead. This control has builtin support for tooltips.

like image 24
bruno conde Avatar answered Oct 04 '22 05:10

bruno conde