Solved

WinForms CheckedListBox control tooltip for items

Posted on 2006-07-08
5
1,559 Views
Last Modified: 2012-06-27
Does anyone know how to set the tooltip for a CheckedListBox item?

I have a bunch of items in my checked list box, and some of the item display names are too wide for the checked list box.

I would like the user to be able to see the entire text of the item in a tooltip.

Thanks!
0
Comment
Question by:gregasm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17067871
Attempt #1:

  Private Sub CheckedListBox1_MouseMove(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles CheckedListBox1.MouseMove

    Dim topIndex As Integer = Me.CheckedListBox1.TopIndex
    Dim itemHeight As Integer = Me.CheckedListBox1.ItemHeight
    Dim index As Integer = (e.Y \ itemHeight) + topIndex
    Dim itemText As String = Me.CheckedListBox1.Items(index)

    If Me.ToolTip1.GetToolTip(Me.CheckedListBox1) <> itemText Then
      Me.ToolTip1.SetToolTip(Me.CheckedListBox1, itemText)
    End If

  End Sub

Bob
0
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 17067873
Hi, one approach would be to handle the CheckedListBox's SelectedIndexChanged event, then set the tooltop of the entire control to whats currently selected:

private void checkedListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
      this.toolTip1.SetToolTip(this.checkedListBox1, this.checkedListBox1.Text);
}

(Drag a tooltop onto your form from the toolbox, it should declare it automatically for you in the code editor)
0
 
LVL 8

Author Comment

by:gregasm
ID: 17068895
A tooltip should not require a selection changed event, only a mouse hover. I like Bob's idea and i think it is going in the right direction, but the entire scenario becomes more involved when we try to use the mouse hover event, and then have to handle clearing the tooltip as well as showing it...

I will try out the samples and see if it gets me anywhere.

Of course, the other solution is to just not do the entire thing if the scope starts to grow too big.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17068968
If you want to use the MouseHover event, then you need to store the current Point, and use that in the MouseHover event, since it doesn't have that information as arguments.

Bob
0
 

Expert Comment

by:dastaub
ID: 37067944
i used the first suggestion and it worked flawlessly.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question