On my WinForms, I have 2 listboxes that are scrolling together using the scrollbar on either listbox.
But I can't seem to get the MouseWheel to do it correctly. Both listboxes scroll together but the listbox I am scrolling will move more lines than the other.
Using the scrollbar, I update the TopIndex on both listboxes. This works great.
What is happening is that when the MouseWheel moves, the event is fired before the original event on the first list box is processed.
For example, I have 2 listboxes (A and B). If I use my MouseWheel on listbox A, the event on listbox B is handled and then the text on listbox A is handled by the OS.
Here If I am on ListBox A and scroll with the wheel, A_MouseWheel will fire and will set B.topIndex to what A.topIndex is. At this point it is 0 since the OS hasn't moved it yet.
Then the OS moves the text and it is now 1. On the next click, B.topIndex will be changed to 1 and then the OS will move the text again on A which will now be 2.
Is there a way to get the event to fire after the original listbox has been handled?
Thanks,
Tom
But I can't seem to get the MouseWheel to do it correctly. Both listboxes scroll together but the listbox I am scrolling will move more lines than the other.
Using the scrollbar, I update the TopIndex on both listboxes. This works great.
What is happening is that when the MouseWheel moves, the event is fired before the original event on the first list box is processed.
For example, I have 2 listboxes (A and B). If I use my MouseWheel on listbox A, the event on listbox B is handled and then the text on listbox A is handled by the OS.
Code:
A.MouseWheel += new MouseEventHandler(A_MouseWheel);
B.MouseWheel += new MouseEventHandler(B_MouseWheel);
void A_MouseWheel(object sender, MouseEventArgs e)
{
B.TopIndex = A.TopIndex;
}
void B_MouseWheel(object sender, MouseEventArgs e)
{
A.TopIndex = B.TopIndex;
}
Here If I am on ListBox A and scroll with the wheel, A_MouseWheel will fire and will set B.topIndex to what A.topIndex is. At this point it is 0 since the OS hasn't moved it yet.
Then the OS moves the text and it is now 1. On the next click, B.topIndex will be changed to 1 and then the OS will move the text again on A which will now be 2.
Is there a way to get the event to fire after the original listbox has been handled?
Thanks,
Tom