Strange behavior with C# (VS 2010) ListView Control mouse click event (items are without checkbox):
private void m_ListView_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
// Returning some times wrong values
ListViewItem lvi = m_ListView.GetItemAt(e.X, e.Y);
//.... more logic here
}
}
After I clicked the item, and immediately I moved the mouse down or up, some other item is getting selected instead of what is intended;
I debugged and came to know that e.X, e.Y is capturing WRONG values. When I click and leave the mouse pointer unmoved, it’s working fine. But if I clicked and immediately moved to another row, one of that row is getting selected instead.
Questions:
- Is this a known issue with ListView mouse events?
- Is there any other way to retrieve correct coordinates for the mouse events?
This is an enterprise level project, where performance is very important. We have written original code for all mouse events like up, down, doubleclick, mouseclick, itemcheck etc.
-Karthik
That should work to get the item that was just clicked (Focused)
Would get the item at the mouse location, which is why it changes when you move the mouse quickly away, if you want the item that you just clicked,
m_ListView.FocusedItemshould work fine