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:
    $LVFN_DIR_LEFT (0) - Left
    $LVFN_DIR_RIGHT (1) - Right
    $LVFN_DIR_UP (2) - Up
    $LVFN_DIR_DOWN (3) - Down
    $LVFN_DIR_START (4) - From start
    $LVFN_DIR_END (5) - From end
    $LVFN_DIR_PRIOR (6) - From prior item
    $LVFN_DIR_NEXT (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()
        ; Create GUI
        GUICreate("ListView Find Nearest (v" & @AutoItVersion & ")", 400, 300)
        Local $idListview = GUICtrlCreateListView("", 2, 2, 394, 268)
        GUICtrlSetStyle($idListview, $LVS_ICON)
        GUISetState(@SW_SHOW)

        ; Set ANSI format
;~     _GUICtrlListView_SetUnicodeFormat($idListview, False)

        ; Load images
        Local $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
        Local $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