Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 59293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:58:57+00:00 2026-05-10T17:58:57+00:00

I have a listbox that is databound to a Collection of objects. The listbox

  • 0

I have a listbox that is databound to a Collection of objects. The listbox is configured to display an identifier property of each object. I would like to show a tooltip with information specific to the item within the listbox that is being hovered over rather than one tooltip for the listbox as a whole.

I am working within WinForms and thanks to some helpful blog posts put together a pretty nice solution, which I wanted to share.

I’d be interested in seeing if there’s any other elegant solutions to this problem, or how this may be done in WPF.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:58:57+00:00Added an answer on May 10, 2026 at 5:58 pm

    There are two main sub-problems one must solve in order to solve this problem:

    1. Determine which item is being hovered over
    2. Get the MouseHover event to fire when the user has hovered over one item, then moved the cursor within the listbox and hovered over another item.

    The first problem is rather simple to solve. By calling a method like the following within your handler for MouseHover, you can determine which item is being hovered over:

    private ITypeOfObjectsBoundToListBox DetermineHoveredItem() {     Point screenPosition = ListBox.MousePosition;     Point listBoxClientAreaPosition = listBox.PointToClient(screenPosition);      int hoveredIndex = listBox.IndexFromPoint(listBoxClientAreaPosition);     if (hoveredIndex != -1)     {         return listBox.Items[hoveredIndex] as ITypeOfObjectsBoundToListBox;     }     else     {         return null;     } } 

    Then use the returned value to set the tool-tip as needed.

    The second problem is that normally the MouseHover event isn’t fired again until the cursor has left the client area of the control and then come back.

    You can get around this by wrapping the TrackMouseEvent Win32API call.
    In the following code, the ResetMouseHover method wraps the API call to get the desired effect: reset the underlying timer that controls when the hover event is fired.

    public static class MouseInput {     // TME_HOVER     // The caller wants hover notification. Notification is delivered as a      // WM_MOUSEHOVER message.  If the caller requests hover tracking while      // hover tracking is already active, the hover timer will be reset.      private const int TME_HOVER = 0x1;      private struct TRACKMOUSEEVENT     {         // Size of the structure - calculated in the constructor         public int cbSize;          // value that we'll set to specify we want to start over Mouse Hover and get         // notification when the hover has happened         public int dwFlags;          // Handle to what's interested in the event         public IntPtr hwndTrack;          // How long it takes for a hover to occur         public int dwHoverTime;          // Setting things up specifically for a simple reset         public TRACKMOUSEEVENT(IntPtr hWnd)         {             this.cbSize = Marshal.SizeOf(typeof(TRACKMOUSEEVENT));             this.hwndTrack = hWnd;             this.dwHoverTime = SystemInformation.MouseHoverTime;             this.dwFlags = TME_HOVER;         }     }      // Declaration of the Win32API function     [DllImport('user32')]     private static extern bool TrackMouseEvent(ref TRACKMOUSEEVENT lpEventTrack);      public static void ResetMouseHover(IntPtr windowTrackingMouseHandle)     {         // Set up the parameter collection for the API call so that the appropriate         // control fires the event         TRACKMOUSEEVENT parameterBag = new TRACKMOUSEEVENT(windowTrackingMouseHandle);          // The actual API call         TrackMouseEvent(ref parameterBag);     } } 

    With the wrapper in place, you can simply call ResetMouseHover(listBox.Handle) at the end of your MouseHover handler and the hover event will fire again even when the cursor stays within the control’s bounds.

    I’m sure this approach, sticking all the code in the MouseHover handler must result in more MouseHover events firing than are really necessary, but it’ll get the job done. Any improvements are more than welcome.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a collection databound to a ListBox . What I would like to
I have a databound ListBox that is behaving strangely. The ListBox's SelectionMode property is
I have a listbox which is databound to a collection of objects. I want
I have a databound listbox on my C# WinForm that holds strings that are
I currently have a listbox that has its selected item bound to a property
I have a ListBox in a grid that gets databound when the page loads...
I have a ListBox (lstBxsources) that is populated correctly and works like it should.
I have a ListBox with a set of values and I would like to
I have a data bound listbox that lists names of items, I am now
How do i databind a listbox to a List that i have in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.