On my x64 Vista PC I am trying to find the index or value of the
WinForms CheckedListBox Item at the current mouse position after a
right click. First I tried using the Click event, but for
CheckedListBox it doesn't fire for a right click. The MouseDown
event fires, I can use the MouseEventArgs argument e.Y to find the
index of the Item, unless the CheckedListBox has been scrolled. I set
the VerticalScroll.Minimum=0; VerticalScroll.Maximum = Items.Count ==
110 for my current test. So far I have tried:
CheckedListBox.AutoScrollOffset.Y
Form.VerticalScroll.Value
Form.AutoScrollPosition.Y
All of these always return 0 regardless of the vertical scrollbar
position. Is there any way to find the index of a right clicked
CheckedListBox Item after vertical scrolling?
Thanks,
invegat
Hi invegat,
Did you try the IndexFromPoint method?
void checkedListBox1_MouseDown(object sender, MouseEventArgs e)
{
int index = checkedListBox1.IndexFromPoint(e.Location);
}
It should take scroll position into account and return the correct index.
--
Happy Coding!
Morten Wennevik [C# MVP]