NMS Posted Monday at 09:55 AM Posted Monday at 09:55 AM So as the title says. Let's say I have 20 items in the list view. I would like to navigate them using arrow keys, however on row's end it will jump to the first item in the next row, and vice-versa. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> GUICreate("test", 500, 600) Global $idListview = GUICtrlCreateListView('', 10, 10, 480, 575, _ BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_NOCOLUMNHEADER, $LVS_REPORT)) _GUICtrlListView_SetView($idListview, 0) For $i = 0 To 20 _GUICtrlListView_AddItem($idListview, $i, $i) Sleep(10) Next GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $iIDFrom, $iCode, $iIndex $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $idListview Switch $iCode Case $LVN_KEYDOWN Local $tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam) Local $iVK = Hex(DllStructGetData($tInfo, "VKey"), 2) $iIndex = _GUICtrlListView_GetSelectedIndices($idListview, True) If $iIndex[0] = 0 Then Return $GUI_RUNDEFMSG Switch $iVK Case 25 ConsoleWrite($iIndex[1] & @CRLF) If Mod($iIndex[1], 11) = 0 Then _GUICtrlListView_SetItemSelected($idListview, $iIndex[1] - 1, True, True) Case 26 ConsoleWrite($iIndex[1] & @CRLF) Case 27 ConsoleWrite($iIndex[1] & @CRLF) If Mod($iIndex[1], 10) = 0 And Not $iIndex[1] = 0 Then _GUICtrlListView_SetItemSelected($idListview, $iIndex[1] + 1, True, True) Case 28 ConsoleWrite($iIndex[1] & @CRLF) EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc The problem I'm having is figuring out why it skips the first item in the next row and directly goes to the next one. I tried various ways of getting the $iIndex however that isn't the issue. From the looks of it the moment I focus the item it "skips" (_GUICtrlListView_SetItemSelected($idListview, $iIndex[1] + 1, True, TRUE). But if I don't focus it can't continue on the next row.
Solution Nine Posted Monday at 01:04 PM Solution Posted Monday at 01:04 PM You need to cancel default behavior of the listview, that way : Case 25 ; left ConsoleWrite("left " & $iIndex[1] & @CRLF) If Mod($iIndex[1], 7) = 0 Then _GUICtrlListView_SetItemSelected($idListview, $iIndex[1] - 1, True, True) Return 1 EndIf NMS 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
NMS Posted Monday at 04:54 PM Author Posted Monday at 04:54 PM 3 hours ago, Nine said: You need to cancel default behavior of the listview, that way : Case 25 ; left ConsoleWrite("left " & $iIndex[1] & @CRLF) If Mod($iIndex[1], 7) = 0 Then _GUICtrlListView_SetItemSelected($idListview, $iIndex[1] - 1, True, True) Return 1 EndIf Yep that makes total sense. Somehow going through the list and not realizing it had its own default behavior didn't occur to me. No need for Mod() either now.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now