开发者

Finding the row and column in a listview that the mouse cursor is over

开发者 https://www.devze.com 2023-01-19 18:32 出处:网络
I have a simple ListView, essentially creating a MxN grid.\"FullRowSelect\" is off.Essentially we have a grid of cells.

I have a simple ListView, essentially creating a MxN grid. "FullRowSelect" is off. Essentially we have a grid of cells.

I am trying to find out of the mouse is over a cell that contains an Item, and if so, what Item it is.

GetItemAt(.开发者_StackOverflow中文版..) is close to what I want to do, but not quite. If there is text in the "cell", then GetItemAt() returns the item. The problem is that if it is over the cell, but not actually over the text in the cell, then it returns null.

I am stumped. Can anyone help me?


There is a bug/"feature" of the ListView concerning hit testing.

If FullRowSelect is false and the point is over cell 0 but not on the text or icon, GetItemAt() will not register a hit.

One hackish way around this is to intercept the low-level LVM_HITTEST message, turn on FullRowSelect, do the normal LVM_HITTEST processing, and then turn FullRowSelect off again. This sort of works but can mess up the tool tip on the underlying control.

An easier way is to use ObjectListView (an open source wrapper around a .NET ListView), which has already solved this (and quite a few other problems) with the standard ListView.

I am the author of this control so, yes, I am biased, but not necessarily inaccurate :)

0

精彩评论

暂无评论...
验证码 换一张
取 消