Setting the Position and Scroll Position of a List View Item
Every list view item has a position and size, which you can retrieve and set using messages. You can also determine which item, if any, is at a specified position. The position of list view items is specified in view coordinates, which are client coordinates offset by the scroll position.
To retrieve and set the position of an item, use the LVM_GETITEMPOSITION and LVM_SETITEMPOSITION messages, respectively. LVM_GETITEMPOSITION works for all views, but LVM_SETITEMPOSITION works only for icon view and small-icon view.
You can determine the item, if any, that is at a particular location by using the LVM_HITTEST message. To retrieve the bounding rectangle for a list item, or for only its icon or its label, use the LVM_GETITEMRECT message.
Unless the LVS_NOSCROLL window style is specified, you can use messages to:
- Scroll a list view control to show items that do not fit in the client area of the control.
- Determine the scroll position of a list view control.
- Scroll a list view control by a specified amount.
- Scroll a list view control so that a specified list item is visible.
In icon view or small-icon view, the current scroll position is defined by the view origin. The view origin is the set of coordinates that correspond to the view coordinates (0, 0), relative to the visible area of the list view control. To get the current view origin, use the LVM_GETORIGIN message. This message should be used only in icon view or small-icon view; it returns an error in list view or report view.
In list view or report view, the current scroll position is defined by the top index. The top index is the index of the first visible item in the list view control. To get the current top index, use the LVM_GETTOPINDEX message. This message returns a valid result only in list view or report view; it returns zero in icon view or small-icon view.
Use the LVM_GETVIEWRECT message to get the bounding rectangle of all of the items in a list view control, relative to the visible area of the control.
The LVM_GETCOUNTPERPAGE message returns the number of items that fit in one page of the list view control. This message returns a valid result only in list view and report view; in icon view and small-icon view, it returns the total number of items.
To scroll a list view control by a specific amount, use the LVM_SCROLL message. By using the LVM_ENSUREVISIBLE message, you can scroll the list view control, if necessary, to ensure that a specified item is visible.
Last updated on Wednesday, April 13, 2005
© 2005 Microsoft Corporation. All rights reserved.