Highlighting items in listbox when mouse moves over them
-
In a comboBox as you move the mouse across the list of items, the item under the mouse is highlighted (without clicking on it). How do you make a list box work the same way? Currently I display a different picture for each item in the listbox as the mouse moves over it, but without it higlighting as I move over it, it is sometimes difficult to tell which item I am drawing for. I have search the internet and several books for this but have not found anything related to this topic. Gary
-
In a comboBox as you move the mouse across the list of items, the item under the mouse is highlighted (without clicking on it). How do you make a list box work the same way? Currently I display a different picture for each item in the listbox as the mouse moves over it, but without it higlighting as I move over it, it is sometimes difficult to tell which item I am drawing for. I have search the internet and several books for this but have not found anything related to this topic. Gary
The simplest way to achieve this is to get the index of the item that is below the mouse using the
IndexFromPoint
and select this item:private void listTest_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
// Get the index of the item below the mouse pointer
int index = listTest.IndexFromPoint(e.X, e.Y);
listTest.SelectedIndex = index;
}Regards Nuri
-
The simplest way to achieve this is to get the index of the item that is below the mouse using the
IndexFromPoint
and select this item:private void listTest_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
// Get the index of the item below the mouse pointer
int index = listTest.IndexFromPoint(e.X, e.Y);
listTest.SelectedIndex = index;
}Regards Nuri
I knew there had to be a simple way to do it, and after seeing this I feel embrassed that I didn't think to try that myself. Thank you very much. Gary