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
Solved

WinForms CheckedListBox control tooltip for items

Posted on 2006-07-08
5
1,535 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

789 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