Jump to content

Two listview, delete the duplicated element.


Go to solution Solved by Andreik,

Recommended Posts

Hi my friend i need help to create a code.

 

I have 2 lists.
List #1 with two columns that has a list of files, the first column has the file name and the full path and the second column has the date.

global $idListview = GUICtrlCreateListView("Archivo a procesar|Fecha",             20, 20, 900, 400, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))

 

 

List #2

The other list also has 2 columns and contains files that I must delete by coincidence from list #1

global $idListview2 = GUICtrlCreateListView("Archivo a procesar|Fecha",             530, 40, 400, 400, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))

 

Help me with a code that does this, 

List #1 contain example

F:\Enel\Backup Full\Dia 5\_srt\DJI_0009.KML

 

List #2 contain example

F:\Enel\Backup Full\Dia 5\_srt\DJI_0009.SRT

 

The element os the list #1:

F:\Enel\Backup Full\Dia 5\_srt\DJI_0009.KML

i need to delete, because the first part of the text repeat F:\Enel\Backup Full\Dia 5\_srt\DJI_0009

 

Reference image attached

 

best reqards

 

2024-08-20_20-25-06.jpg

Link to comment
Share on other sites

  • Solution

Not tested as a fully script but something like this:

#include <Array.au3>
#include <GuiListView.au3>

; Create GUI here

$aList1 = ListColumnToArray($cList1, 1)     ; $cList1 - handle or ctrl id of the first list
$aList2 = ListColumnToArray($cList2, 1)     ; $cList2 - handle or ctrl id of the second list

For $Index = 1 To $aList1[0]
    _ArraySearch($aList2, StringReplace($aList1[$Index], '.kml', '.srt'))
    If Not @error Then _GUICtrlListView_DeleteItem($cList1, $Index - 1)
Next

Func ListColumnToArray($List, $Column)
    Local $sData
    If $Column > _GUICtrlListView_GetColumnCount($List) Then Return SetError(1, 0, Null)
    Local $NumOfItems = _GUICtrlListView_GetItemCount($List)
    For $Index = 0 To $NumOfItems - 1
        $sData &= _GUICtrlListView_GetItemText($List, $Index, $Column) & '|'
    Next
    Return StringSplit(StringTrimRight($sData, 1), '|')
EndFunc

 

Link to comment
Share on other sites

15 hours ago, Andreik said:

Not tested as a fully script but something like this:

#include <Array.au3>
#include <GuiListView.au3>

; Create GUI here

$aList1 = ListColumnToArray($cList1, 1)     ; $cList1 - handle or ctrl id of the first list
$aList2 = ListColumnToArray($cList2, 1)     ; $cList2 - handle or ctrl id of the second list

For $Index = 1 To $aList1[0]
    _ArraySearch($aList2, StringReplace($aList1[$Index], '.kml', '.srt'))
    If Not @error Then _GUICtrlListView_DeleteItem($cList1, $Index - 1)
Next

Func ListColumnToArray($List, $Column)
    Local $sData
    If $Column > _GUICtrlListView_GetColumnCount($List) Then Return SetError(1, 0, Null)
    Local $NumOfItems = _GUICtrlListView_GetItemCount($List)
    For $Index = 0 To $NumOfItems - 1
        $sData &= _GUICtrlListView_GetItemText($List, $Index, $Column) & '|'
    Next
    Return StringSplit(StringTrimRight($sData, 1), '|')
EndFunc

 

Very good job as always Andreik, it worked on the first try, thank you very much

Best regards

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...