Jump to content

GUIListViewEx, Drag&Drop and filter


Go to solution Solved by marcoauto,

Recommended Posts

Ciao,
I'm trying to filter a draggable Listview using checkbox, but when I filter a listview (idListiview) and I drag and drop a record to another listview, the listview that i filtered returns not filtered and the record that i would drag and drop is not the correct one
There are 4 listview, LISTVIEWL1, LISTVIEWL2, LISTVIEWL3 and LISTVIEW. The filter must be work for LISTVIEW (and they work)
Where I wrong?
This is my script (Is not complete, but I rewrite it for the forum)

I know that is not an optimized script...
 
Thanks and sorry for my bad english
 
Marco
 

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <EditConstants.au3>
#include "GUIListViewEx.au3"
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include "_FileListToArrayEx_Marco.au3"
#include <Array.au3>

; *******************************************************************************************************
; **************************** LETTURA FILE CODICI DALLE CARTELLE ***************************************
; *******************************************************************************************************

;~ $listaTotaleCodici = _FileListToArrayEx ("images", "*.png", 4);1+4); 1+4+128)   ;<== original
dim $listaTotaleCodici[11]
$listaTotaleCodici[0] = 10
$listaTotaleCodici[1] = "01A_COD1_Tipo1_CHECK2_01_123456789_02_.png"
$listaTotaleCodici[2] = "01A_COD2_Tipo1_CHECK3_02_321456789_01_.png"
$listaTotaleCodici[3] = "02A_COD1_Tipo1_CHECK2_01_231456798_02_.png"
$listaTotaleCodici[4] = "03A_COD1_Tipo2_CHECK1_01_888456789_01_.png"
$listaTotaleCodici[5] = "04A_COD2_Tipo2_CHECK1_01_111456789_02_.png"
$listaTotaleCodici[6] = "05A_COD1_Tipo1_CHECK2_01_777456789_02_.png"
$listaTotaleCodici[7] = "05A_COD1_Tipo3_CHECK1_01_666456789_01_.png"
$listaTotaleCodici[8] = "06A_COD1_Tipo1_CHECK2_01_555456789_02_.png"
$listaTotaleCodici[9] = "07A_COD1_Tipo3_CHECK2_01_444456789_01_.png"
$listaTotaleCodici[10] = "08A_COD1_Tipo1_CHECK2_01_666777789_02_.png"
;~ $listaTotaleCodici[11] = "08A_COD2_Tipo1_CHECK3_01_222456789_02_.png"



; read some png files
; Ex:
; 01A_COD_Tipo1_CHECK2_N_NUMBER_XY.png
; 02A_COD_Tipo1_CHECK2_N_NUMBER_XY.png
; 03A_COD_Tipo3_CHECK1_N_NUMBER_XY.png
; where NUMBER is differentfor any png files
; COD has max 2 values (COD1 or COD2)
; Tipo has max 3 values

; *******************************************************************************************************
; ********************************* DICHIARAZIONI VARIABILI *********************************************
; *******************************************************************************************************

dim $aArray[8]
dim $filtrare[13] ;array dove vengono memorizzate le parole da filtrare (899, 01, webcom, ecc ecc)
Global $fatto = 0
Global $iLV_L1,$iLV_L2,$iLV_L3,$iLV_Codici
Dim $idItem[800]
Dim $idItemL1[3]
Dim $idItemL2[3]
Dim $idItemL3[3]

Global $idListviewL1, $idListviewL2, $idListviewL3, $idListview

$x = 120
$y = 96
$offsetxpreview = 24+100
$offsetypreview = 129+96
$offsetx = $offsetxpreview + $x + 24
$offsety = 12
Global $offsetxradio = 345

Global $aList1, $tmp_String
Dim $TotaleCodici[800]
Dim $aTempArray[800]
Dim $idButton[6]
Global $offsetxbutton = 20
Global $offsetybutton = 45
Global $idx=0
Global $b = 0
Global $filtrato = 0


; *******************************************************************************************************
; **************************************** PARTENZA GDI *************************************************
; *******************************************************************************************************

_GDIPlus_Startup()
;~ GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")


; *******************************************************************************************************
; *********************************** CREAZIONE GUI PRINCIPALE ******************************************
; *******************************************************************************************************

$g_hGUI = GUICreate("GUI", 1038, 700, 192, 124)
GUISetState()

Global $Graphic = _GDIPlus_GraphicsCreateFromHWND($g_hGUI)

; *******************************************************************************************************
; **************************************** CREAZIONE CHECKBOX  ******************************************
; *******************************************************************************************************

GUIStartGroup()
$RadioCodice1 = GUICtrlCreateCheckbox("CHECK1", $offsetxradio+112, 10, 100, 17)
GUICtrlSetState($RadioCodice1, $GUI_CHECKED)
$RadioCodice2 = GUICtrlCreateCheckbox("CHECK2", $offsetxradio+227, 10, 100, 17)
GUICtrlSetState($RadioCodice2, $GUI_CHECKED)
$RadioCodice3 = GUICtrlCreateCheckbox("CHECK3", $offsetxradio+341, 10, 100, 17)
GUICtrlSetState($RadioCodice3, $GUI_CHECKED)
$Label1 = GUICtrlCreateLabel("LABEL:", $offsetxradio + 24 + 35, 10+2, 50, 17)

$RadioTipo1 = GUICtrlCreateCheckbox("Tipo1", $offsetxradio+112, 45, 100, 17)
GUICtrlSetState($RadioTipo1, $GUI_CHECKED)
$RadioTipo2 = GUICtrlCreateCheckbox("Tipo2", $offsetxradio+227, 45, 100, 17)
GUICtrlSetState($RadioTipo2, $GUI_CHECKED)
$RadioTipo3 = GUICtrlCreateCheckbox("Tipo3", $offsetxradio+341, 45, 100, 17)
GUICtrlSetState($RadioTipo3, $GUI_CHECKED)
$LabelTipo = GUICtrlCreateLabel("TIPO:", $offsetxradio + 24 + 35, 45+2, 50, 17)

Global $offsetxradio = 345
;~ GUIStartGroup()
$Radio1 = GUICtrlCreateCheckbox("A", $offsetxradio+112, 80, 50, 17)
;~  Local $idCheckbox = GUICtrlCreateCheckbox("Standard Checkbox", 10, 10, 185, 25)
GUICtrlSetState($Radio1, $GUI_CHECKED)
$Radio2 = GUICtrlCreateCheckbox("B", $offsetxradio+169, 80, 50, 17)
GUICtrlSetState($Radio2, $GUI_CHECKED)
$Radio3 = GUICtrlCreateCheckbox("C", $offsetxradio+227, 80, 50, 17)
GUICtrlSetState($Radio3, $GUI_CHECKED)
$Radio4 = GUICtrlCreateCheckbox("D", $offsetxradio+284, 80, 50, 17)
GUICtrlSetState($Radio4, $GUI_CHECKED)
$Radio5 = GUICtrlCreateCheckbox("E", $offsetxradio+341, 80, 50, 17)
GUICtrlSetState($Radio5, $GUI_CHECKED)
$Radio6 = GUICtrlCreateCheckbox("F", $offsetxradio+399, 80, 50, 17)
GUICtrlSetState($Radio6, $GUI_CHECKED)
$Radio7 = GUICtrlCreateCheckbox("ALL", $offsetxradio+456, 80, 50, 17)
GUICtrlSetState($Radio7, $GUI_CHECKED)
$LabelGruppi = GUICtrlCreateLabel("LABEL:", $offsetxradio + 24 + 35, 80+2, 50, 17)

$ButtonFiltra = GUICtrlCreateButton("Filter", 870, 12, 150, 84)
;~ GUICtrlSetBkColor(-1,0x00FF00

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($Graphic)
$hPen = _GDIPlus_PenCreate(0xff000000, 2);red, 3pixels wide

; *******************************************************************************************************
; **************************************** CREAZIONE BOTTONI  *******************************************
; *******************************************************************************************************

$cDelete_Button = GUICtrlCreateButton("Delete Line", 870, 115, 150, 30)


$idListviewL1 = GUICtrlCreateListView("LISTVIEWL1", 400, 6+96, 450, 96)
_GUICtrlListView_SetColumnWidth($idListviewL1, 0, 446)
$idListviewL2 = GUICtrlCreateListView("LISTVIEWL2", 400, 6+96+96, 450, 96)
_GUICtrlListView_SetColumnWidth($idListviewL2, 0, 446)
$idListviewL3 = GUICtrlCreateListView("LISTVIEWL3", 400, 6+96+96+96, 450, 96)
_GUICtrlListView_SetColumnWidth($idListviewL3, 0, 446)
$idListview = GUICtrlCreateListView("LISTVIEW", 400, 6+96+96+96+96, 450, 573-96-96-96)
_GUICtrlListView_SetColumnWidth($idListview, 0, 446)

if $fatto = 0 Then
    ConsoleWrite("fatto = 0" & @CRLF)
    For $i = 1 To $listaTotaleCodici[0] ; Loop through the array to display the individual values.
        local $aArray = StringSplit($listaTotaleCodici[$i], '_');, $STR_ENTIRESPLIT) ; Pass the variable to StringSplit and using the delimiter "\n".
        Local $aList[$listaTotaleCodici[0]+1], $sText
        If IsArray($aArray) Then
            $sText =  $aArray[1] & " " & $aArray[2] &  " " & $aArray[3] &  " " & $aArray[4] &  " " & $aArray[6]
            $aList[$i] = $sText
            GUICtrlCreateListViewItem($sText, $idListview)
        EndIf
    Next
    $iLV_Codici = _GUIListViewEx_Init($idListview, $aList, 0, 0, True, 128 + 256)
    $TotaleEtichetteCodici = _GUIListViewEx_ReadToArray($idListview)
    $fatto = 1
EndIf

$iLV_L1 = _GUIListViewEx_Init($idListviewL1, $idItemL1, 0, 0, True) ; No external drop, will drag to others - items deleted on drag
$iLV_L2 = _GUIListViewEx_Init($idListviewL2, $idItemL2, 0, 0, True) ; No external drop, will drag to others - items deleted on drag
$iLV_L3 = _GUIListViewEx_Init($idListviewL3, $idItemL3, 0, 0, True) ; No external drop, will drag to others - items deleted on drag
;~  $iLV_Codici = _GUIListViewEx_Init($idListview, $idItem, 0, 0, True, 128 + 256) ; No external drop, will drag to others - items NOT deleted on drag
;~  GUISetState()
_GUIListViewEx_MsgRegister()

_GUICtrlListView_SetColumnWidth($idListview, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($idListview, 1, 1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; *******************************************************************************************************
; ********************************************* MAIN LOOP ***********************************************
; *******************************************************************************************************

Global $idMsg
;~     ; Loop until the user exits.
    While 1
        Sleep(10)
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cDelete_Button
                $listaTotaleCodiciaAttiva = _GUIListViewEx_GetActive()
                ConsoleWrite(" active = " & $listaTotaleCodiciaAttiva & @CRLF)
                if $listaTotaleCodiciaAttiva <> 1 Then
                    _GUIListViewEx_Delete()
                EndIf
            Case $ButtonFiltra
                _filtraCodici()
        EndSwitch
    WEnd

; Clean up resources
_GDIPlus_GraphicsDispose($Graphic)
_GDIPlus_Shutdown()


; *******************************************************************************************************
; ***************************************** QUIT FUNCTION ***********************************************
; *******************************************************************************************************

Func Quit()

    _GDIPlus_Shutdown()
    Exit
EndFunc


; *******************************************************************************************************
; **************************************** ISCHECKED FUNCTION *******************************************
; *******************************************************************************************************

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked


; *******************************************************************************************************
; ************************************ WM_NOTIFY FUNCTION ***********************************************
; *******************************************************************************************************

Func WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    _GUIListViewEx_WM_NOTIFY_Handler($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $index
    $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    $hWndFrom = DllStructGetData($tStruct, 1)
    $idFrom = DllStructGetData($tStruct, 2)
    $code = DllStructGetData($tStruct, 3)
    $index = DllStructGetData($tStruct, 4)
    $hWndListView1 = GUICtrlGetHandle($iLV_L1) ;($idListviewL1)
    $hWndListView2 = GUICtrlGetHandle($iLV_L2) ;($idListviewL2)
    $hWndListView3 = GUICtrlGetHandle($iLV_L3) ;($idListviewL3)
    $hWndListViewCodici = GUICtrlGetHandle($iLV_Codici) ;($idListview)
    Switch $code
        Case $NM_CLICK  ;Left Mouse Button
            ConsoleWrite("left mouse button")
            Switch $idFrom
                Case $iLV_L1
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
;~                     ConsoleWrite("+Click: " & $index & @CRLF)
                    $text = _GUICtrlListView_GetItemText($iLV_L1, DllStructGetData($tInfo, "Index"))
                    ConsoleWrite("+text: " & $text & @CRLF)
            EndSwitch

        Case $NM_DBLCLK ;Double Left Mouse Button
            Switch $idFrom
                Case $idListviewL1
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
;~                     ConsoleWrite("+Click: " & $index & @CRLF)
                    $text = _GUICtrlListView_GetItemText($idListviewL1, DllStructGetData($tInfo, "Index"))
                    ConsoleWrite("+textDBClick: " & $text & @CRLF)
                Case $idListview
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
;~                     ConsoleWrite("+Click: " & $index & @CRLF)
                    $text = _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"))
                    ConsoleWrite("+textDBClick: " & $text & @CRLF)
            EndSwitch

        Case $GUI_EVENT_CLOSE
            Quit()

    EndSwitch
EndFunc   ;==>WM_NOTIFY


; *******************************************************************************************************
; ***************************************** FILTRA CODICI ***********************************************
; *******************************************************************************************************

Func _filtraCodici()
            $aTempArray = $TotaleEtichetteCodici ;$listaTotaleCodici
            Local $filtrato = 0
            If _IsChecked($Radio1) Then
        $filtrare[1] = 1
    Else
        $filtrare[1] = "A"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = StringLeft($aTempArray[$b][0],3)
            If StringInStr($tmp_String,$filtrare[1]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($Radio2) Then
        $filtrare[2] = 1
    Else
        $filtrare[2] = "B"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = StringLeft($aTempArray[$b][0],3)
            If StringInStr($tmp_String,$filtrare[2]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($Radio3) Then
        $filtrare[3] = 1
    Else
        $filtrare[3] = "C"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = StringLeft($aTempArray[$b][0],3)
            If StringInStr($tmp_String,$filtrare[3]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($Radio4) Then
        $filtrare[4] = 1
    Else
        $filtrare[4] = "D"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = StringLeft($aTempArray[$b][0],3)
            If StringInStr($tmp_String,$filtrare[4]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($Radio5) Then
        $filtrare[5] = 1
    Else
        $filtrare[5] = "E"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = StringLeft($aTempArray[$b][0],3)
            If StringInStr($tmp_String,$filtrare[5]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($Radio6) Then
        $filtrare[6] = 1
    Else
        $filtrare[6] = "F"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = StringLeft($aTempArray[$b][0],3)
            If StringInStr($tmp_String,$filtrare[6]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($RadioTipo1) Then
        $filtrare[7] = 1
    Else
        $filtrare[7] = "Tipo1"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = $aTempArray[$b][0]
            If StringInStr($tmp_String,$filtrare[7]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($RadioTipo2) Then
        $filtrare[8] = 1
    Else
        $filtrare[8] = "Tipo2"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            $tmp_String = $aTempArray[$b][0]
            If StringInStr($tmp_String,$filtrare[8]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($RadioTipo3) Then
        $filtrare[9] = 1
    Else
        $filtrare[9] = "Tipo3"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            $tmp_String = $aTempArray[$b][0]
            If StringInStr($tmp_String,$filtrare[9]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($RadioCodice1) Then
        $filtrare[10] = 1
    Else
        $filtrare[10] = "CHECK1"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = $aTempArray[$b][0]
            If StringInStr($tmp_String,$filtrare[10]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($RadioCodice2) Then
        $filtrare[11] = 1
    Else
        $filtrare[11] = "CHECK2"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = $aTempArray[$b][0]
    ;~      ConsoleWrite(@CRLF & "$tmp_Stringgg= " & $tmp_String & @CRLF)
            If StringInStr($tmp_String,$filtrare[11]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($RadioCodice3) Then
        $filtrare[12] = 1
    Else
        $filtrare[12] = "CHECK3"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = $aTempArray[$b][0]
    ;~      ConsoleWrite(@CRLF & "$tmp_Stringgg= " & $tmp_String & @CRLF)
            If StringInStr($tmp_String,$filtrare[12]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf
    _ArrayDisplay($aTempArray,"fine ciclo")
    _GUICtrlListView_DeleteAllItems($idListview)
;~  $iLV_Codici = _GUIListViewEx_Close($idListview)
    ConsoleWrite("_GUICtrlListView_DeleteAllItems" & @CRLF)
    IF $filtrato = 0 Then
        For $a=0 to UBound($TotaleEtichetteCodici)-1 ; Loop through the array to display the individual values.
            Local $aList1[UBound($TotaleEtichetteCodici)], $sText
            If IsArray($TotaleEtichetteCodici) Then
                $sText =  $TotaleEtichetteCodici[$a][0]
                ConsoleWrite("sText non filtrato = " & $sText & @CRLF)
                $aList1[$a] = $sText
                GUICtrlCreateListViewItem($sText, $idListview)
            EndIf
        Next
    EndIf
    if $filtrato = 1 Then
        For $a=0 to UBound($aTempArray)-1 ; Loop through the array to display the individual values.
            Global $aList1[UBound($aTempArray)], $sText
            If IsArray($aTempArray) Then
                $sText =  $aTempArray[$a][0]
                ConsoleWrite("sText = " & $sText & @CRLF)
                $aList1[$a] = $sText
                GUICtrlCreateListViewItem($sText, $idListview)
            EndIf
        Next
    EndIf
    $iLV_Codici = _GUIListViewEx_Close($idListview)
    $iLV_Codici = _GUIListViewEx_Init($idListview, $aList1, 0, 0, True, 128 + 256); 0, 0, True, 1 + 2 + 8, "0;2")

EndFunc     ;==>_filtraCodici
Link to comment
Share on other sites

After you drag and drop you'll have to run the _filtraCodici() function to re-sort your items.

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

You cannot in your script, as it is not the script that handles the drag and drop.

You'll need to modify the GUIListViewEx.au3 functions for the drag and drop to run _filtraCodici() after all is said and done.

In the _GUIListViewEx_WM_LBUTTONUP_Handler() function. put _filtraCodici() at the end like so:

; #FUNCTION# =========================================================================================================
; Name...........: _GUIListViewEx_WM_LBUTTONUP_Handler
; Description ...: Windows message handler for WM_NOTIFY
; Syntax.........: _GUIListViewEx_WM_LBUTTONUP_Handler()
; Requirement(s).: v3.3 +
; Return values .: None
; Author ........: Melba23
; Modified ......:
; Remarks .......: If a WM_LBUTTONUP handler already registered, then call this function from within that handler
; Example........: Yes
;=====================================================================================================================
Func _GUIListViewEx_WM_LBUTTONUP_Handler($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam, $lParam

    If Not $iGLVEx_Dragging Then
        Return "GUI_RUNDEFMSG"
    EndIf

    ; Get item count
    Local $iMultipleItems = $iGLVEx_Dragging - 1

    ; Reset flag
    $iGLVEx_Dragging = 0

    ; Get window under mouse cursor
    Local $hCurrent_Wnd = _GUIListViewEx_GetCursorWnd()

    ; Abandon if mouse not within tgt ListView
    If $hCurrent_Wnd <> $hGLVEx_TgtHandle Then
        ; Clear insert mark
        _GUICtrlListView_SetInsertMark($hGLVEx_TgtHandle, -1, True)
        ; Reset highlight to original items in Src ListView
        For $i = 0 To $iMultipleItems
            _GUIListViewEx_Highlight($hGLVEx_TgtHandle, $cGLVEx_TgtID, $iGLVEx_DraggedIndex + $i)
        Next
        ; Delete copied arrays
        $aGLVEx_SrcArray = 0
        $aGLVEx_TgtArray = 0
        Return
    EndIf

    ; Clear insert mark
    _GUICtrlListView_SetInsertMark($hGLVEx_TgtHandle, -1, True)

    ; Clear drag image
    If $hGLVEx_DraggedImage Then
        _GUIImageList_DragLeave($hGLVEx_SrcHandle)
        _GUIImageList_EndDrag()
        _GUIImageList_Destroy($hGLVEx_DraggedImage)
        $hGLVEx_DraggedImage = 0
    EndIf

    ; Dropping within same ListView
    If $hGLVEx_SrcHandle = $hGLVEx_TgtHandle Then
        ; Determine position to insert
        If $fGLVEx_BarUnder Then
            If $iGLVEx_DraggedIndex > $iGLVEx_InsertIndex Then $iGLVEx_InsertIndex += 1
        Else
            If $iGLVEx_DraggedIndex < $iGLVEx_InsertIndex Then $iGLVEx_InsertIndex -= 1
        EndIf

        ; Check not dropping on dragged item(s)
        Switch $iGLVEx_InsertIndex
            Case $iGLVEx_DraggedIndex To $iGLVEx_DraggedIndex + $iMultipleItems
                ; Reset highlight to original items
                For $i = 0 To $iMultipleItems
                    _GUIListViewEx_Highlight($hGLVEx_SrcHandle, $cGLVEx_SrcID, $iGLVEx_DraggedIndex + $i)
                Next
                ; Delete copied arrays
                $aGLVEx_SrcArray = 0
                $aGLVEx_TgtArray = 0
                Return
        EndSwitch

        ; Create Local array for checkboxes (if no checkboxes makes no difference)
        Local $aCheck_Array[UBound($aGLVEx_SrcArray)]
        For $i = 1 To UBound($aCheck_Array) - 1
            $aCheck_Array[$i] = _GUICtrlListView_GetItemChecked($hGLVEx_SrcHandle, $i - 1)
        Next

        ; Create Local array for dragged items checkbox state
        Local $aCheckDrag_Array[$iMultipleItems + 1]

        ; Amend arrays
        ; Get data from dragged element(s)
        If $iMultipleItems Then
            ; Multiple dragged elements
            Local $aInsertData[$iMultipleItems + 1]
            For $i = 0 To $iMultipleItems
                Local $aItemData[UBound($aGLVEx_SrcArray, 2)]
                For $j = 0 To UBound($aGLVEx_SrcArray, 2) - 1
                    $aItemData[$j] = $aGLVEx_SrcArray[$iGLVEx_DraggedIndex + 1 + $i][$j]
                Next
                $aInsertData[$i] = $aItemData
                $aCheckDrag_Array[$i] = _GUICtrlListView_GetItemChecked($hGLVEx_SrcHandle, $iGLVEx_DraggedIndex + $i)
            Next
        Else
            ; Single dragged element
            Local $aInsertData[1]
            Local $aItemData[UBound($aGLVEx_SrcArray, 2)]
            For $i = 0 To UBound($aGLVEx_SrcArray, 2) - 1
                $aItemData[$i] = $aGLVEx_SrcArray[$iGLVEx_DraggedIndex + 1][$i]
            Next
            $aInsertData[0] = $aItemData
            $aCheckDrag_Array[0] = _GUICtrlListView_GetItemChecked($hGLVEx_SrcHandle, $iGLVEx_DraggedIndex)
        EndIf

        ; Delete dragged element(s) from arrays
        For $i = 0 To $iMultipleItems
            _GUIListViewEx_Array_Delete($aGLVEx_SrcArray, $iGLVEx_DraggedIndex + 1)
            _GUIListViewEx_Array_Delete($aCheck_Array, $iGLVEx_DraggedIndex + 1)
        Next

        ; Amend insert positon for multiple items deleted above
        If $iGLVEx_DraggedIndex < $iGLVEx_InsertIndex Then
            $iGLVEx_InsertIndex -= $iMultipleItems
        EndIf

        ; Re-insert dragged element(s) into array
        For $i = $iMultipleItems To 0 Step -1
            _GUIListViewEx_Array_Insert($aGLVEx_SrcArray, $iGLVEx_InsertIndex + 1, $aInsertData[$i])
            _GUIListViewEx_Array_Insert($aCheck_Array, $iGLVEx_InsertIndex + 1, $aCheckDrag_Array[$i])
        Next

        ; Rewrite ListView to match array
        _GUIListViewEx_ReWriteLV($hGLVEx_SrcHandle, $aGLVEx_SrcArray, $aCheck_Array, $iGLVEx_SrcIndex)

        ; Set highlight to inserted item(s)
        For $i = 0 To $iMultipleItems
            _GUIListViewEx_Highlight($hGLVEx_SrcHandle, $cGLVEx_SrcID, $iGLVEx_InsertIndex + $i)
        Next

        ; Store amended array
        $aGLVEx_Data[$aGLVEx_Data[0][1]][2] = $aGLVEx_SrcArray
        ; Delete copied arrays
        $aGLVEx_SrcArray = 0
        $aGLVEx_TgtArray = 0

    Else ; Dropping in another ListView

        ; Determine position to insert
        If $fGLVEx_BarUnder Then
            $iGLVEx_InsertIndex += 1
        EndIf

        ; Amend array
        ; Get data from dragged element(s)
        If $iMultipleItems Then
            ; Multiple dragged elements
            Local $aInsertData[$iMultipleItems + 1]
            For $i = 0 To $iMultipleItems
                Local $aItemData[UBound($aGLVEx_SrcArray, 2)]
                For $j = 0 To UBound($aGLVEx_SrcArray, 2) - 1
                    $aItemData[$j] = $aGLVEx_SrcArray[$iGLVEx_DraggedIndex + 1 + $i][$j]
                Next
                $aInsertData[$i] = $aItemData
            Next
        Else
            ; Single dragged element
            Local $aInsertData[1]
            Local $aItemData[UBound($aGLVEx_SrcArray, 2)]
            For $i = 0 To UBound($aGLVEx_SrcArray, 2) - 1
                $aItemData[$i] = $aGLVEx_SrcArray[$iGLVEx_DraggedIndex + 1][$i]
            Next
            $aInsertData[0] = $aItemData
        EndIf

        ; Delete dragged element(s) from source array
        If Not BitAnd($aGLVEx_Data[$iGLVEx_SrcIndex][12], 4) Then
            For $i = 0 To $iMultipleItems
                _GUIListViewEx_Array_Delete($aGLVEx_SrcArray, $iGLVEx_DraggedIndex + 1)
            Next
        EndIf
        ; Check if insert index is valid
        If $iGLVEx_InsertIndex  < 0 Then
            $iGLVEx_InsertIndex = _GUICtrlListView_GetItemCount($hGLVEx_TgtHandle)
        EndIf
        ; Insert dragged element(s) into target array
        For $i = $iMultipleItems To 0 Step -1
            _GUIListViewEx_Array_Insert($aGLVEx_TgtArray, $iGLVEx_InsertIndex + 1, $aInsertData[$i])
            ;$aGLVEx_TgtArray[0][0] += 1
        Next

        ; Rewrite ListViews to match arrays
        _GUIListViewEx_ReWriteLV($hGLVEx_SrcHandle, $aGLVEx_SrcArray, $aGLVEx_SrcArray, $iGLVEx_SrcIndex, False)
        _GUIListViewEx_ReWriteLV($hGLVEx_TgtHandle, $aGLVEx_TgtArray, $aGLVEx_TgtArray, $iGLVEx_TgtIndex, False)
        ; Note no checkbox array needed ListViews with them are not interdraggable, so repass normal array and set final parameter

        ; Set highlight to inserted item(s)
        _GUIListViewEx_SetActive($iGLVEx_TgtIndex)
        For $i = 0 To $iMultipleItems
            _GUIListViewEx_Highlight($hGLVEx_TgtHandle, $cGLVEx_TgtID, $iGLVEx_InsertIndex + $i)
        Next

        ; Store amended arrays
        $aGLVEx_Data[$iGLVEx_SrcIndex][2] = $aGLVEx_SrcArray
        $aGLVEx_Data[$iGLVEx_TgtIndex][2] = $aGLVEx_TgtArray

    EndIf

    ; Delete copied arrays
    $aGLVEx_SrcArray = 0
    $aGLVEx_TgtArray = 0
    _filtraCodici() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< HERE

EndFunc   ;==>_GUIListViewEx_WM_LBUTTONUP_Handler

Then, you'll need to include your script #include "myscript.au3" at the top. Or you can put the entire function in your script and comment out it in the library (which will comment it out for everything that uses this UDF).

EDIT: Grammar 

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Ciao,

I've done, but one error occurs again:

If you have time try this:

- Run the program

- Drag the second record from Listview to listviewl1 (01A COD2 Tipo1 CHECK3 321456789)

- uncheck CHECK3 and click the Filter button

- all the records in the "LISTVIEW" with CHECK3 are hidden (and it's ok)

- drag and drop second record (02A COD1 Tipo1 CHECK2 231456798) to LISTVIEWL1 and in the LISTVIEWL1 the result is the wrong record (01A COD2 Tipo1 CHECK3 321456789), the filtered one

Seems that the drag and drop function doesn't use the new filtered listview array.

Marco

Link to comment
Share on other sites

Yes, it has to do with the way the array internally is reflecting with your filtering.

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

  • Solution

ciao

I found the solution!!

I chenged the line

$iLV_Codici = _GUIListViewEx_Close($idListview)

 with

$iLV_Codici = _GUIListViewEx_Close(1)

in my function _filtraCodici() just before the end

So I close and erase the Listview (that is the number 1) and after I re-init the listview whit the new array

I have also deleted the _filtraCodici() in the GUIListViewEx.au3 because is no longer necessary.

Below the new _filtraCodici()

Thanks again MikahS for all

marco

Func _filtraCodici()
            $aTempArray = $TotaleEtichetteCodici ;$listaTotaleCodici
            Local $filtrato = 0
            If _IsChecked($Radio1) Then
        $filtrare[1] = 1
    Else
        $filtrare[1] = "A"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = StringLeft($aTempArray[$b][0],3)
            If StringInStr($tmp_String,$filtrare[1]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($Radio2) Then
        $filtrare[2] = 1
    Else
        $filtrare[2] = "B"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = StringLeft($aTempArray[$b][0],3)
            If StringInStr($tmp_String,$filtrare[2]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($Radio3) Then
        $filtrare[3] = 1
    Else
        $filtrare[3] = "C"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = StringLeft($aTempArray[$b][0],3)
            If StringInStr($tmp_String,$filtrare[3]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($Radio4) Then
        $filtrare[4] = 1
    Else
        $filtrare[4] = "D"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = StringLeft($aTempArray[$b][0],3)
            If StringInStr($tmp_String,$filtrare[4]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($Radio5) Then
        $filtrare[5] = 1
    Else
        $filtrare[5] = "E"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = StringLeft($aTempArray[$b][0],3)
            If StringInStr($tmp_String,$filtrare[5]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($Radio6) Then
        $filtrare[6] = 1
    Else
        $filtrare[6] = "F"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = StringLeft($aTempArray[$b][0],3)
            If StringInStr($tmp_String,$filtrare[6]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($RadioTipo1) Then
        $filtrare[7] = 1
    Else
        $filtrare[7] = "Tipo1"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = $aTempArray[$b][0]
            If StringInStr($tmp_String,$filtrare[7]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($RadioTipo2) Then
        $filtrare[8] = 1
    Else
        $filtrare[8] = "Tipo2"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            $tmp_String = $aTempArray[$b][0]
            If StringInStr($tmp_String,$filtrare[8]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($RadioTipo3) Then
        $filtrare[9] = 1
    Else
        $filtrare[9] = "Tipo3"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            $tmp_String = $aTempArray[$b][0]
            If StringInStr($tmp_String,$filtrare[9]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($RadioCodice1) Then
        $filtrare[10] = 1
    Else
        $filtrare[10] = "CHECK1"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = $aTempArray[$b][0]
            If StringInStr($tmp_String,$filtrare[10]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($RadioCodice2) Then
        $filtrare[11] = 1
    Else
        $filtrare[11] = "CHECK2"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = $aTempArray[$b][0]
    ;~      ConsoleWrite(@CRLF & "$tmp_Stringgg= " & $tmp_String & @CRLF)
            If StringInStr($tmp_String,$filtrare[11]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf

    If _IsChecked($RadioCodice3) Then
        $filtrare[12] = 1
    Else
        $filtrare[12] = "CHECK3"
        $filtrato = 1
        For $b=UBound($aTempArray) -1 to 0 step -1
            Global $tmp_String = $aTempArray[$b][0]
    ;~      ConsoleWrite(@CRLF & "$tmp_Stringgg= " & $tmp_String & @CRLF)
            If StringInStr($tmp_String,$filtrare[12]) Then
                 _ArrayDelete($aTempArray, $b)
            EndIf
        Next
    EndIf
;~  _ArrayDisplay($aTempArray,"fine ciclo")
    _GUICtrlListView_DeleteAllItems($idListview)
;~  $iLV_Codici = _GUIListViewEx_Close($idListview)
    ConsoleWrite("_GUICtrlListView_DeleteAllItems" & @CRLF)
    IF $filtrato = 0 Then
        For $a=0 to UBound($TotaleEtichetteCodici)-1 ; Loop through the array to display the individual values.
            Local $aList1[UBound($TotaleEtichetteCodici)], $sText
            If IsArray($TotaleEtichetteCodici) Then
                $sText =  $TotaleEtichetteCodici[$a][0]
                ConsoleWrite("sText non filtrato = " & $sText & @CRLF)
                $aList1[$a] = $sText
                GUICtrlCreateListViewItem($sText, $idListview)
            EndIf
        Next
    EndIf
    if $filtrato = 1 Then
        For $a=0 to UBound($aTempArray)-1 ; Loop through the array to display the individual values.
            Global $aList1[UBound($aTempArray)], $sText
            If IsArray($aTempArray) Then
                $sText =  $aTempArray[$a][0]
                ConsoleWrite("sText = " & $sText & @CRLF)
                $aList1[$a] = $sText
                GUICtrlCreateListViewItem($sText, $idListview)
            EndIf
        Next
    EndIf
    $iLV_Codici = _GUIListViewEx_Close(1)       ;<==ADDED THIS LINE Close and erase the LISTVIEW
    $iLV_Codici = _GUIListViewEx_Init($idListview, $aList1, 0, 0, True, 128 + 256); 0, 0, True, 1 + 2 + 8, "0;2")

EndFunc     ;==>_filtraCodici
Link to comment
Share on other sites

Glad you got it figured out. It's my pleasure.  ^_^

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...