By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,973 Members | 1,854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,973 IT Pros & Developers. It's quick & easy.

ListView GetItemAt (e.X, e.Y) method

P: n/a
Hi all,

When I try to use the GetItemAt (e.X, e.Y) method in a ListView MouseDown()
event, it only works some of the time. If I right-click on an open area of
the ListView, I get null back as expected. If I right-click on a
ListViewItem, I get that ListViewItem back. But then... if I right-click on
an open area of the ListView again I get the last ListViewItem I clicked on
back... I'm sure there's a way around this. GetItemAt doesn't seem to be
holding onto the last value returned. I did something similar with the
TreeView GetNodeAt method, and it works as advertised. Anyone have any
ideas on this?

Thanks in advance,
Michael C.
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Michael,

I normally do this way, which is pretty accurate in retrieving items. You
can use this code, on mousehover, or mousemove, or mouse down event.

//use cursor points.
Point p = lstViewTest.PointToClient(new Point (Cursor.Position.X
,Cursor.Position.Y));

//now get the item.
ListViewItem pItem = lstViewTest.GetItemAt(p.X,p.Y )

Shak

"Michael C" <mi*******@optonline.net> wrote in message
news:4Q*********************@news4.srv.hcvlny.cv.n et...
Hi all,

When I try to use the GetItemAt (e.X, e.Y) method in a ListView MouseDown() event, it only works some of the time. If I right-click on an open area of the ListView, I get null back as expected. If I right-click on a
ListViewItem, I get that ListViewItem back. But then... if I right-click on an open area of the ListView again I get the last ListViewItem I clicked on back... I'm sure there's a way around this. GetItemAt doesn't seem to be
holding onto the last value returned. I did something similar with the
TreeView GetNodeAt method, and it works as advertised. Anyone have any
ideas on this?

Thanks in advance,
Michael C.

Nov 16 '05 #2

P: n/a
Thanks Shakir,

It looks like my bug was caused by a context menu I was using, but wasn't
clearing out between pop-ups. I used your code with the Clear() method of
the pop-up event for the context menu and it works great now!

Thanks,
Michael C.

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Michael,

I normally do this way, which is pretty accurate in retrieving items. You
can use this code, on mousehover, or mousemove, or mouse down event.

//use cursor points.
Point p = lstViewTest.PointToClient(new Point (Cursor.Position.X
,Cursor.Position.Y));

//now get the item.
ListViewItem pItem = lstViewTest.GetItemAt(p.X,p.Y )

Shak

"Michael C" <mi*******@optonline.net> wrote in message
news:4Q*********************@news4.srv.hcvlny.cv.n et...
Hi all,

When I try to use the GetItemAt (e.X, e.Y) method in a ListView MouseDown()
event, it only works some of the time. If I right-click on an open area

of
the ListView, I get null back as expected. If I right-click on a
ListViewItem, I get that ListViewItem back. But then... if I right-click on
an open area of the ListView again I get the last ListViewItem I clicked

on
back... I'm sure there's a way around this. GetItemAt doesn't seem to

be holding onto the last value returned. I did something similar with the
TreeView GetNodeAt method, and it works as advertised. Anyone have any
ideas on this?

Thanks in advance,
Michael C.


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.