2

I have a ListView with 4 items, and 3 subitems in each item.

Now, for example, I'd want to get the coordinates(position) relative to the Form for item 2, subitem 2.

How can I do it?

Eugene Podskal
  • 10,270
  • 5
  • 31
  • 53
spunit
  • 523
  • 2
  • 6
  • 23
  • x and y yes. For the Form. – spunit Aug 17 '14 at 12:08
  • Seems like http://stackoverflow.com/questions/4998076/getting-the-location-of-a-control-relative-to-the-entire-screen – Eugene Podskal Aug 17 '14 at 12:54
  • With that I can only get list.PointToScreen(Point.Empty); I want to get like list.Items[1].SubItems[1].PointToScreen(Point.Empty); (but that gives errors) – spunit Aug 17 '14 at 13:02
  • Yes, looks like [SubItem](http://msdn.microsoft.com/en-Us/library/system.windows.forms.listviewitem.listviewsubitem(v=vs.110).aspx) is not a control, so it does not have `PointToScreen` method. – Eugene Podskal Aug 17 '14 at 13:14
  • 2
    http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewitem.listviewsubitem.bounds%28v=vs.110%29.aspx – Hans Passant Aug 17 '14 at 13:49
  • Thanks. But I don't understand how to use that... Maybe an example? – spunit Aug 17 '14 at 14:48

1 Answers1

4

You are looking for Bounds property of a ListViewSubItem. Here is a simple usage of the property:

private void listView1_MouseDown(object sender, MouseEventArgs e)
{
    var bound = listView1.Items[1].SubItems[1].Bounds;

    if (e.X > bound.Left && e.X < bound.Right && e.Y > bound.Top && e.Y < bound.Bottom)
    {
        MessageBox.Show("hello world");
    }
}
nevets
  • 4,631
  • 24
  • 40