public int NearestIndex(Point_ pt) { double distance = Double.MaxValue; int nearest = -1; for (int i = 0; i < listview_owner.Items.Count; i++) { Point_ pos = listview_owner.GetItemLocation(i); double d = Math.Pow(pos.X - pt.X, 2) + Math.Pow(pos.Y - pt.Y, 2); if (d < distance) { distance = d; nearest = i; } } if (listview_owner.item_control.dragged_item_index == nearest) { return(-1); } return(nearest); }