System.Windows.Forms.ListView.GetItemAt Method

Retrieves the item at the specified location.

Syntax

public ListViewItem GetItemAt (int x, int y)

Parameters

x
The x-coordinate of the location to search for an item (expressed in client coordinates).
y
The y-coordinate of the location to search for an item (expressed in client coordinates).

Returns

A System.Windows.Forms.ListViewItem that represents the item at the specified position. If there is no item at the specified location, the method returns null.

Remarks

The ListView.GetItemAt(int, int) method lets you determine which item is located at a specific location within the client region of the System.Windows.Forms.ListView control. You can use this method when the user clicks or right-clicks a subitem (when the ListView.View property is set to View.Details) and you want to determine which item owns the subitem that was clicked based on the mouse coordinates at the time the user clicked the mouse.

Note:

When the ListView.FullRowSelect property value is false, this method returns an item only when the specified location is within the bounds of the parent item (which is displayed in the first column when the control is in details mode). You must set the ListView.FullRowSelect property to true to retrieve an item with this method given a location within the bounds of a subitem. You can also use the erload:System.Windows.Forms.ListView.HitTest method to retrieve detailed information about the item at a particular location.

To do drag-and-drop repositioning of items within a System.Windows.Forms.ListView, you might want to use the ListViewInsertionMark.NearestIndex(System.Drawing.Point) method rather than the ListView.GetItemAt(int, int) method. The ListViewInsertionMark.NearestIndex(System.Drawing.Point) method finds the closest item regardless of where the mouse pointer is located. The ListView.GetItemAt(int, int) method, on the other hand, returns null if there is no item at the specified location.

Note:

The System.Windows.Forms.ListViewInsertionMark class is supported only on Windows XP and Windows Server 2003 when your application calls the Application.EnableVisualStyles method.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0