- pt
- A System.Drawing.Point representing the location from which to find the nearest item.
The index of the item closest to the specified point or -1 if the closest item is the item currently being dragged.
This method lets you locate the item closest to the mouse pointer when doing a drag-and-drop operation. Use the index value returned to set the ListViewInsertionMark.Index property. When the item closest to the mouse pointer is the item being dragged, the return value of this method is -1. In this case, setting the ListViewInsertionMark.Index property to this value hides the insertion mark.
This method finds the closest item regardless of where the mouse pointer is located, while the ListView.GetItemAt(int, int) method returns the item at the specified location only, or null if there is no item at that location. The ListView.GetItemAt(int, int) method returns null, for example, when the mouse pointer is located between two items. For this reason, you should always use the ListViewInsertionMark.NearestIndex(System.Drawing.Point) method when using a drag-and-drop operation to position items.