Search the Community
Showing results for tags 'arrow keys'.
-
Any idea how to change this example from LarsJ so that the selection via arrow keys works for marked cells? ;coded by LarsJ #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 Global $aLV = [ [ 0, 25, 45, -1, -1 ], _ ; $hLV, $iLVx, $iLVy, $aHit[0], $aHit[1] [ 0, 125, 145, -1, -1 ], _ [ 0, 225, 245, -1, -1 ] ] Example() Func Example() $hGui = GUICreate( "Mark Cell in Listview", 500, 520 ) Local $idTab = GUICtrlCreateTab( 10, 10, 480, 500 ) GUICtrlCreateTabItem( "Tab 0, LV 0" ) Local $idLV0 = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 25, 45, 250, 250 ) For $i = 0 To 99 GUICtrlCreateListViewItem( "Cell " & $i & ".0" & "|Cell " & $i & ".1" & "|Cell " & $i & ".2", $idLV0 ) Next $hLV = GUICtrlGetHandle( $idLV0 ) $aLV[0][0] = $hLV $iLVx = 25 $iLVy = 45 GUICtrlCreateTabItem( "Tab 1, LV 1" ) Local $idLV1 = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 125, 145, 250, 250 ) For $i = 0 To 99 GUICtrlCreateListViewItem( "Cell " & $i & ".0" & "|Cell " & $i & ".1" & "|Cell " & $i & ".2", $idLV1 ) Next $aLV[1][0] = GUICtrlGetHandle( $idLV1 ) GUICtrlCreateTabItem( "Tab 2, LV 2" ) Local $idLV2 = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 225, 245, 250, 250 ) For $i = 0 To 99 GUICtrlCreateListViewItem( "Cell " & $i & ".0" & "|Cell " & $i & ".1" & "|Cell " & $i & ".2", $idLV2 ) Next $aLV[2][0] = GUICtrlGetHandle( $idLV2 ) GUICtrlCreateTabItem( "" ) GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) GUISetState() Local $iTab, $iTabPrev = 0 While 1 Switch GUIGetMsg() Case $idTab $iTab = GUICtrlRead( $idTab ) $aLV[$iTabPrev][3] = $aHit[0] $aLV[$iTabPrev][4] = $aHit[1] $hLV = $aLV[$iTab][0] $iLVx = $aLV[$iTab][1] $iLVy = $aLV[$iTab][2] $aHit[0] = $aLV[$iTab][3] $aHit[1] = $aLV[$iTab][4] If $aHit[0] <> -1 Then _ _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] ) $iTabPrev = $iTab Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc 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 Switch $iCode 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 $aHit[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
- 12 replies
-
- listview
- arrow keys
-
(and 1 more)
Tagged with: