Search the Community
Showing results for tags 'Multi select'.
-
I want that the Listview acts as CTRL key was pressed by default to avoid any deletion when the listview was clicked. Here an example code: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> $hGUI = GUICreate("ListView Test", 400, 550) $iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)) _GUICtrlListView_AddColumn($iLV, "Date", 100, 1) _GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1) _GUICtrlListView_AddColumn($iLV, "File Name", 100, 1) For $i = 0 to 150 _GUICtrlListView_AddItem($iLV, "Row " & $i) _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1) _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2) Next $cButton = GUICtrlCreateButton("Reset", 10, 510, 80, 30) GUISetState() _GUICtrlListView_SetItemChecked($iLV, 0) _GUICtrlListView_SetItemSelected($iLV, 0) _GUICtrlListView_SetItemChecked($iLV, 1) _GUICtrlListView_SetItemSelected($iLV, 1) _GUICtrlListView_SetItemChecked($iLV, 2) _GUICtrlListView_SetItemSelected($iLV, 2) ControlFocus($hGUI, "", $iLV) ; Create array to hold selection state Global $aSelected[_GUICtrlListView_GetItemCount($iLV)] GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton ; Clear all selections _GUICtrlListView_SetItemSelected($iLV, -1, False) ; Clear selected array Global $aSelected[_GUICtrlListView_GetItemCount($iLV)] EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) If @error Then Return Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = HWnd($tNMHDR.hWndFrom) Local $iIDFrom = $tNMHDR.IDFrom Local $iCode = $tNMHDR.Code Local Static $iCount = 0 Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Switch $iCode Case $LVN_ITEMCHANGED If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then Switch $tInfo.NewState Case 8192 ;item checked _GUICtrlListView_SetItemSelected($iLV, $tInfo.Item, True) Case 4096 ;item unchecked _GUICtrlListView_SetItemSelected($iLV, $tInfo.Item, False) EndSwitch EndIf Case $NM_CLICK $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) ;~ _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ ;~ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ ;~ "-->Code:" & @TAB & $iCode & @CRLF & _ ;~ "-->Index:" & @TAB & $tInfo.Index & @CRLF & _ ;~ "-->SubItem:" & @TAB & $tInfo.SubItem & @CRLF & _ ;~ "-->NewState:" & @TAB & $tInfo.NewState & @CRLF & _ ;~ "-->OldState:" & @TAB & $tInfo.OldState & @CRLF & _ ;~ "-->Changed:" & @TAB & $tInfo.Changed & @CRLF & _ ;~ "-->ActionX:" & @TAB & $tInfo.ActionX & @CRLF & _ ;~ "-->ActionY:" & @TAB & $tInfo.ActionY & @CRLF & _ ;~ "-->lParam:" & @TAB & $tInfo.lParam & @CRLF & _ ;~ "-->KeyFlags:" & @TAB & $tInfo.KeyFlags) _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, _GUICtrlListView_GetItemState($iLV, $tInfo.Index, $LVIS_SELECTED)) EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc Func _DebugPrint($s_Text , $sLine = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @CRLF & _ "+======================================================" & @CRLF & _ "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _ "+======================================================" & @CRLF) EndFunc ;==>_DebugPrint Just cklick the listview and you will see that the selection is deleted. Repeat it and hold the CTRL key pressed. Any ideas? I don't want to read the listview and check whether the checkbox is checked and mark the row appropriately! It's lagging... Thanks, UEZ