Function Reference


_GUICtrlListView_FindNearest

Finds the item nearest to the position specified

#include <GuiListView.au3>
_GUICtrlListView_FindNearest ( $hWnd, $iX, $iY [, $iDir = 0 [, $iStart = -1 [, $bWrapOK = True]]] )

Parameters

$hWnd Control ID/Handle to the control
$iX X position
$iY Y position
$iDir [optional] Specifies which direction to search:
    0 - Left
    1 - Right
    2 - Up
    3 - Down
    4 - From start
    5 - From end
    6 - From prior item
    7 - From next item
$iStart [optional] 0-based index of the item to begin the search with or -1 to start from the beginning.
The specified item is itself excluded from the search.
$bWrapOK [optional] If True, the search will continue with the first item if no match is found

Return Value

Success: the 0-based index of the item.
Failure: -1.

Remarks

This function is supported only by large icon and small icon modes.

Related

_GUICtrlListView_FindItem

Example

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $hImage, $iIndex, $idListview

    ; Create GUI
    GUICreate("ListView Find Nearest", 400, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUICtrlSetStyle($idListview, $LVS_ICON)
    GUISetState(@SW_SHOW)

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($idListview), 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($idListview), 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($idListview), 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($idListview, $hImage, 0)

    ; Add items
    _GUICtrlListView_AddItem($idListview, "Item 1", 0)
    _GUICtrlListView_AddItem($idListview, "Item 2", 1)
    _GUICtrlListView_AddItem($idListview, "Item 3", 2)

    ; Find nearest items
    $iIndex = _GUICtrlListView_FindNearest($idListview, 100, 10)
    MsgBox($MB_SYSTEMMODAL, "Information", "Item nearest [100, 10]: " & $iIndex)

    $iIndex = _GUICtrlListView_FindNearest($idListview, 200, 10)
    MsgBox($MB_SYSTEMMODAL, "Information", "Item nearest [200, 10]: " & $iIndex)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example