Hat jemand ein Idee, wie ich den Code erweitern kann, sodass die Selektion mit den Pfeiltasten nach oben / unten verschoben werden kann?
AutoIt
;coded by LarsJ
#include <Array.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
Opt("MustDeclareVars", 1)
Global $hGui, $hLV, $iLVx, $iLVy, $aHit[2] = [-1, -1] ; $aHit contains row & col of marked cell
Example()
Func Example()
$hGui = GUICreate("Mark Cell in Listview", 500, 540)
Local $idLV0 = GUICtrlCreateListView("Column 0|Column 1|Column 2", 25, 10, 250, 500)
For $i = 0 To 99
GUICtrlCreateListViewItem("Cell " & $i & ".0" & "|Cell " & $i & ".1" & "|Cell " & $i & ".2", $idLV0)
Next
$hLV = GUICtrlGetHandle($idLV0)
$iLVx = 25
$iLVy = 10
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
EndFunc ;==>Example
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local $tNMHDR, $hWndFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hLV
Local $iSelectedItem = _GUICtrlListView_GetSelectionMark($hLV)
ConsoleWrite(_GUICtrlListView_GetSelectedIndices($hLV) & @CRLF)
Switch $iCode
; Handle arrow key presses for selection movement
Case $LVN_KEYDOWN
Local $tNMLVKEYDOWN = DllStructCreate($tagNMLVKEYDOWN, $lParam)
Local $iVKey = DllStructGetData($tNMLVKEYDOWN, "VKey")
;~ If $iSelectedItem > -1 Then
;~ Local $iNewIndex = -1
;~ If $iVKey = 38 Then ; Up arrow key
;~ $iNewIndex = $iSelectedItem - 1
;~ ElseIf $iVKey = 40 Then ; Down arrow key
;~ $iNewIndex = $iSelectedItem + 1
;~ EndIf
;~ ConsoleWrite($iNewIndex & @CRLF)
;~ If $iNewIndex > -1 And $iNewIndex < _GUICtrlListView_GetItemCount($hLV) Then
;~ _GUICtrlListView_SetItemSelected($hLV, $iNewIndex, True, False)
;~ _GUICtrlListView_RedrawItems($hLV, $iNewIndex, $iNewIndex)
;~ EndIf
;~ EndIf
Case $LVN_ITEMCHANGED
Local $tNMLISTVIEW, $iItem, $aInfo
$tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
$iItem = DllStructGetData($tNMLISTVIEW, "Item")
_GUICtrlListView_SetItemSelected($hLV, $iItem, False)
_GUICtrlListView_SetItemState($hLV, $iItem, 0, $LVIS_FOCUSED)
Local $aInfo = GUIGetCursorInfo($hGui)
If $aInfo[2] Then
$aInfo = _GUICtrlListView_SubItemHitTest($hLV, $aInfo[0] - $iLVx, $aInfo[1] - $iLVy)
If $aInfo[0] > -1 And $aInfo[1] > -1 And $aInfo[0] = $iItem Then
If $aHit[0] > -1 Then _GUICtrlListView_RedrawItems($hLV, $aHit[0], $aHit[0])
If $aHit[0] <> $aInfo[0] Or $aHit[1] <> $aInfo[1] Then
$aHit[0] = $aInfo[0] ; Row
$aHit[1] = $aInfo[1] ; Col
Else
$aHit[0] = -1 ; Row
$aHit[1] = -1 ; Col
EndIf
_GUICtrlListView_RedrawItems($hLV, $iItem, $iItem)
EndIf
EndIf
Case $NM_CUSTOMDRAW
Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
Switch $dwDrawStage ; Holds a value that specifies the drawing stage
Case $CDDS_PREPAINT ; Before the paint cycle begins
Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations
Case $CDDS_ITEMPREPAINT ; Before painting an item
Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any SUBITEM-related drawing operations
Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Before painting a subitem
Local $dwItemSpec = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index
Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index
Local $uItemState = DllStructGetData($tNMLVCUSTOMDRAW, "uItemState") ; Item state
If $dwItemSpec = $aHit[0] Then ; Marked row
Switch $iSubItem
Case 0 To 1 ; Marked column
DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF) ; Forecolor white
DllStructSetData($tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600) ; Backcolor dark blue, BGR
Case Else ; Other columns
DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000) ; Forecolor black
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF) ; Backcolor white
EndSwitch
Else ; Other rows
DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000)
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF)
EndIf
Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Alles anzeigen
Wichtig ist, dass nur die ersten zwei Zellen markiert bleiben.