Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Find Vertical Scroll Position for CheckedListBox

31 views
Skip to first unread message

nospam@invegat

unread,
Jan 19, 2009, 8:03:07 PM1/19/09
to
Hi,

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


Morten Wennevik [C# MVP]

unread,
Jan 20, 2009, 1:58:10 AM1/20/09
to

"nospam@invegat" wrote:

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]

nospam@invegat

unread,
Jan 20, 2009, 9:49:04 PM1/20/09
to
Thanks! IndexFromPoint works great, including when scrolling.
0 new messages