I want to set the tooltip for items present in the List Box when they are hovered over. I am using the following code from this question : How can I set different Tooltip text for each item in a listbox?
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;
}
The hovered index is always -1 and as a result I am getting null. Any suggestions..