Jump to content

Delete duplicate in ListView


Go to solution Solved by incepator,

Recommended Posts

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 213, 209, 456, 343)
$ListView1 = GUICtrlCreateListView("nr|name", 0, 0, 210, 158)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlCreateListViewItem("1|test", $ListView1)
GUICtrlCreateListViewItem("2|new", $ListView1)
GUICtrlCreateListViewItem("3|test", $ListView1)
GUICtrlCreateListViewItem("4|nice", $ListView1)
$Button1 = GUICtrlCreateButton("delete duplicates", 24, 168, 107, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        
    EndSwitch
WEnd

Hello,

I have a problem with this script.

How to make function, for delete duplicates intro ListView..?

Thanks`

Link to comment
Share on other sites

Here you go (not tested):

#include <GUIListView.au3>

...
$hListView = GUICtrlGetHandle($ListView1)

Local $iItemCount = _GUICtrlListView_GetItemCount($hListView)
Local $aItem[$iItemCount], $iFilled = 0, $iDeleted = 0

For $i = 0 To $iItemCount -1
    $sItemText = _GUICtrlListView_GetItemTextString($hListView, $i - $iDeleted)

    If _ArraySearch($aItem, $sItemText) = -1 Then
        $aItem[$iFilled] = $sItemText
        $iFilled += 1
    Else
        _GUICtrlListView_DeleteItem($hListView, $i)
        $iDeleted += 1
    EndIf
Next

Br, FireFox.

Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 213, 209, 456, 343)
$ListView1 = GUICtrlCreateListView("nr|name", 0, 0, 210, 158)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlCreateListViewItem("1|test", $ListView1)
GUICtrlCreateListViewItem("2|new", $ListView1)
GUICtrlCreateListViewItem("3|test", $ListView1)
GUICtrlCreateListViewItem("4|nice", $ListView1)
$Button1 = GUICtrlCreateButton("delete duplicates", 24, 168, 107, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $hListView = GUICtrlGetHandle($ListView1)

            Local $iItemCount = _GUICtrlListView_GetItemCount($hListView)
            Local $aItem[$iItemCount], $iFilled = 0, $iDeleted = 0

            For $i = 0 To $iItemCount -1
                $sItemText = _GUICtrlListView_GetItemTextString($hListView, $i - $iDeleted)

                If _ArraySearch($aItem, $sItemText) = -1 Then
                    $aItem[$iFilled] = $sItemText
                    $iFilled += 1
                Else
                    _GUICtrlListView_DeleteItem($hListView, $i)
                    $iDeleted += 1
                EndIf
            Next
    EndSwitch
WEnd

Thanks @FireFox...but not working ...

^Probably because contain 2 items per/row. (exemple: 1|text ) and compare this items with (3|text ) ...i don't know

Edited by incepator
Link to comment
Share on other sites

...not working...

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 213, 209, 456, 343)
$ListView1 = GUICtrlCreateListView("nr|name", 0, 0, 210, 158)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlCreateListViewItem("1|test", $ListView1)
GUICtrlCreateListViewItem("2|new", $ListView1)
GUICtrlCreateListViewItem("3|test", $ListView1)
GUICtrlCreateListViewItem("4|nice", $ListView1)
$Button1 = GUICtrlCreateButton("delete duplicates", 24, 168, 107, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $hListView = GUICtrlGetHandle($ListView1)

            Local $iItemCount = _GUICtrlListView_GetItemCount($hListView)

            Local $aItem[$iItemCount], $iFilled = 0, $iDeleted = 0

            For $i = 0 To $iItemCount -1
                $sItemText = _GUICtrlListView_GetItemTextString($hListView, $i - $iDeleted)
                $split_string = StringSplit($sItemText,"|")

                If _ArraySearch($aItem, $split_string[2]) = -1 Then
                    $aItem[$iFilled] = $split_string[2]
                    $iFilled += 1
                Else
                    _GUICtrlListView_DeleteItem($hListView, $i)
                    $iDeleted += 1
                EndIf

            Next
    EndSwitch
WEnd

Thanks for your suggestion.

Edited by incepator
Link to comment
Share on other sites

  • 2 weeks later...

I made 2 scripts for this problem, but none works perfectly, if anyone has a better exemple would be grateful...

Exemple 1.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 213, 209, 456, 343)
$ListView1 = GUICtrlCreateListView("nr|name", 0, 0, 210, 158)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlCreateListViewItem("1|test", $ListView1)
GUICtrlCreateListViewItem("2|one", $ListView1)
GUICtrlCreateListViewItem("3|test", $ListView1)
GUICtrlCreateListViewItem("4|test", $ListView1)
GUICtrlCreateListViewItem("5|fb", $ListView1)
GUICtrlCreateListViewItem("6|fb", $ListView1)
GUICtrlCreateListViewItem("7|night", $ListView1)
$Button1 = GUICtrlCreateButton("Del Dup", 24, 168, 107, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1

            $hListView = GUICtrlGetHandle($ListView1)
            Local $iItemCount = _GUICtrlListView_GetItemCount($hListView)
            Local $aItem[$iItemCount], $iFilled = 0, $iDeleted = 0

            For $i = 0 To $iItemCount -1
                $sItemText = _GUICtrlListView_GetItemTextString($hListView, $i - $iDeleted)
                $split_string = StringSplit($sItemText,"|")

                If _ArraySearch($aItem, $split_string[2]) = -1 Then
                    $aItem[$iFilled] = $split_string[2]
                    $iFilled += 1
                Else
                    _GUICtrlListView_DeleteItem($hListView, $i)
                EndIf
            Next

    EndSwitch
WEnd

Exemple 2.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 479, 446, 192, 124)
$ListView1 = GUICtrlCreateListView("nr|List", 8, 8, 458, 406)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 222)
GUICtrlCreateListViewItem("1|test", $ListView1)
GUICtrlCreateListViewItem("2|one", $ListView1)
GUICtrlCreateListViewItem("3|test", $ListView1)
GUICtrlCreateListViewItem("4|test", $ListView1)
GUICtrlCreateListViewItem("5|fb", $ListView1)
GUICtrlCreateListViewItem("6|fb", $ListView1)
GUICtrlCreateListViewItem("7|night", $ListView1)
$Button1 = GUICtrlCreateButton("Del Dup", 56, 416, 75, 25)
$Input1 = GUICtrlCreateInput("", 160, 424, 121, 21)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            For $i = 1 To _GUICtrlListView_GetItemCount($ListView1)
                $keyword = _GUICtrlListView_GetItemText($ListView1, $i-1,1)
                While True
                    $exist =  _GUICtrlListView_FindInText($ListView1, $keyword)
                    If $exist = -1 Then
                        ExitLoop
                    Else
                        _GUICtrlListView_DeleteItem($ListView1,$exist)
                    EndIf

                WEnd
            Next

            GUICtrlSetData($Input1,"Total: "&_GUICtrlListView_GetItemCount($ListView1))
    EndSwitch
WEnd
Link to comment
Share on other sites

This is one of the many ways to do it:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 213, 209, 456, 343)
$ListView1 = GUICtrlCreateListView("nr|name", 0, 0, 210, 158)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlCreateListViewItem("1|test", $ListView1)
GUICtrlCreateListViewItem("2|one", $ListView1)
GUICtrlCreateListViewItem("3|test", $ListView1)
GUICtrlCreateListViewItem("4|test", $ListView1)
GUICtrlCreateListViewItem("5|fb", $ListView1)
GUICtrlCreateListViewItem("6|fb", $ListView1)
GUICtrlCreateListViewItem("7|night", $ListView1)
$Button1 = GUICtrlCreateButton("Del Dup", 24, 168, 107, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $all[200]

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            For $n = 0 to _GUICtrlListView_GetItemCount($ListView1) - 1
                $aaa = StringSplit(_GUICtrlListView_GetItemTextString($ListView1, $n),"|")
                $all[$n] = $aaa[2]
            Next
            _ArrayDupes($all,  1,  0)                ; delete duplicate array content

            For $i = UBound($all) - 1 To 0 Step -    1    ; delete array element if array element = "" (blank)
                If $all[$i] = "" Then _ArrayDelete($all, $i)
            Next

            _GUICtrlListView_DeleteAllItems($ListView1)            ; delete all of the ListView content

            For $n = 0 to Ubound($all) - 1                    ; display a new ListView content
                GUICtrlCreateListViewItem($n + 1 & "|" & $all[$n], $ListView1)
            Next

    EndSwitch
WEnd

;===============================================================================
;
; Description:  _ArrayDupes; deletes duplicates in an Array 1D
; Syntax:           _ArrayDupes(ByRef $ar_Array)
; Parameter(s):        $ar_Array = 1d Array
; Requirement(s):   None
; Return Value(s):  On Success     - Returns  array of  duplicates; options for unique or details of all
;                                - byref Returns a sorted array with no duplicates
;                        On Failure -
;                        @Error=1 P
;                        @Error=2
;
; Author(s):        randallc
;===============================================================================
Func _ArrayDupes(ByRef $arrItemsF, $iDelete = 0, $iDetails = 0)
    local $timerstamp1 = TimerInit()
    If @OSTYPE = "WIN32_WINDOWS"  Then Return 0
    If not IsArray($arrItemsF) then   Return 0
    Local $arrItems = $arrItemsF
    Local $i = 0, $k = 0, $objDictionary = ObjCreate("Scripting.Dictionary"), $arrItemsDupes[UBound($arrItems)]
    Local $objDictDupes = ObjCreate("Scripting.Dictionary")
    For $strItem In $arrItems
        If Not $objDictionary.Exists($strItem) Then
            $objDictionary.Add($strItem, $strItem)
        Else
            If $iDetails Then
                $arrItemsDupes[$k] = $strItem & "|Dupes|" & $i
            Else
                If Not $objDictDupes.Exists($strItem) Then $objDictDupes.Add($strItem, $strItem)
            EndIf
            $k += 1
        EndIf
        $i += 1
    Next
    ReDim $arrItems[$objDictionary.Count ]
    If $k = 0 Then ReDim $arrItemsDupes[1 ]
    If $k > 0 Then ReDim $arrItemsDupes[$k ]
    $i = 0
    If $iDelete Then
        For $strKey In $objDictionary.Keys
            $arrItems[$i] = $strKey
            $i += 1
        Next
        $arrItemsF = $arrItems ;array deleted dupes
    EndIf
    $i = 0
    If Not $iDetails Then
        For $strKey In $objDictDupes.Keys
            $arrItemsDupes[$i] = $strKey
            $i += 1
        Next
        If $i > 0 Then ReDim $arrItemsDupes[$i]
    EndIf
    ConsoleWrite("Total Time= " & Round(TimerDiff($timerstamp1)) & "" & @TAB & " msec" & @LF)
    Return $arrItemsDupes
EndFunc   ;==>_ArrayDupes
Link to comment
Share on other sites

  • Moderators

incepator,

This works when I try it: :)

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Global $aData[] = ["1|test", "2|one", "3|test", "4|test", "5|fb", "6|fb", "7|night"]
Global $aUnique[UBound($aData) + 1] = [0]

$hGUI = GUICreate("Form1", 500, 500)
$cListView = GUICtrlCreateListView("nr|List", 10, 10, 450, 400)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 250)

For $i = 0 To UBound($aData) - 1
    $sData = StringSplit($aData[$i], "|")[2]
    _ArraySearch($aUnique, $sData, 1)
    If @error Then
        $aUnique[0] += 1
        $aUnique[$aUnique[0]] = $sData
        GUICtrlCreateListViewItem($aData[$i], $cListView)
    EndIf
Next

$Input1 = GUICtrlCreateInput("", 160, 424, 121, 21)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
And you can keep using the same code with the $aUnique array when you add further items to the ListView. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

incepator,

Sorry - use the Beta or run this with 3.3.8.1: :)

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Global $aData[7] = ["1|test", "2|one", "3|test", "4|test", "5|fb", "6|fb", "7|night"]
Global $aUnique[UBound($aData) + 1] = [0]

$hGUI = GUICreate("Form1", 500, 500)
$cListView = GUICtrlCreateListView("nr|List", 10, 10, 450, 400)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 250)

For $i = 0 To UBound($aData) - 1
    $aSplit = StringSplit($aData[$i], "|")
    $sData = $aSplit[2]
    _ArraySearch($aUnique, $sData, 1)
    If @error Then
        $aUnique[0] += 1
        $aUnique[$aUnique[0]] = $sData
        GUICtrlCreateListViewItem($aData[$i], $cListView)
    EndIf
Next

$Input1 = GUICtrlCreateInput("", 160, 424, 121, 21)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

very interesting, now trying to retrieve data between work listview.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 287, 442, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 24, 384, 75, 25)
$ListView1 = GUICtrlCreateListView("nr|text|save", 8, 16, 250, 326)
GUICtrlCreateListViewItem("1|one|one 1", $ListView1)
GUICtrlCreateListViewItem("2|one|one 2", $ListView1)
GUICtrlCreateListViewItem("3|test|one 3", $ListView1)
GUICtrlCreateListViewItem("4|test|one 4", $ListView1)
GUICtrlCreateListViewItem("5|fb|one 5", $ListView1)
GUICtrlCreateListViewItem("6|fb|one 6", $ListView1)
GUICtrlCreateListViewItem("7|night|one 7", $ListView1)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Local $nr
            $total = _GUICtrlListView_GetItemCount($ListView1) - 1
            For $i0 = 0 To $total
            $nr &= _GUICtrlListView_GetItemText($ListView1, $i0,0)&"|"&_GUICtrlListView_GetItemText($ListView1, $i0,1)&"|"&_GUICtrlListView_GetItemText($ListView1, $i0,2)&"|"
                ;Global $aData[7] = ["1|test", "2|one", "3|test", "4|test", "5|fb", "6|fb", "7|night"]
        Next
        Global $aData[$total] = [$nr]


        Global $aUnique[UBound($aData) + 1] = [0]

$hGUI = GUICreate("Form1", 500, 500)
$cListView = GUICtrlCreateListView("nr|List|new", 10, 10, 450, 400)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)

For $i = 0 To UBound($aData) - 1
    $sData = StringSplit($aData[$i], "|")
    $final = $sData[2]
    _ArraySearch($aUnique, $final, 1)
    If @error Then
        $aUnique[0] += 1
        $aUnique[$aUnique[0]] = $final
        GUICtrlCreateListViewItem($aData[$i], $cListView)
    EndIf
Next




    EndSwitch
WEnd
Link to comment
Share on other sites

  • Moderators

incepator,

Before I even look in detail at that code, I would like some explanation of the end state for this script. I see that we now have 3 columns - not 2 - in the original listview and that we now create another listview in a child GUI. :o

I am not wasting my time coding possible solutions when I have no idea of what you are actually trying to do, as when people change the goalposts mid-thread the decisions taken to solve the initial problem are often not those which lend themselves to the final overall solution. ;)

So over to you to explain exactly what you are doing here and what problems you are encountering. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

the idea is that the items number 3 must maintain position ...I attached an exemple ...thanks :)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 213, 209, 456, 343)
$ListView1 = GUICtrlCreateListView("nr|name|href", 0, 0, 210, 158)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlCreateListViewItem("1|test|alg 1", $ListView1)
GUICtrlCreateListViewItem("2|one|alg 2", $ListView1)
GUICtrlCreateListViewItem("3|test|alg 3", $ListView1)
GUICtrlCreateListViewItem("4|test|alg 4", $ListView1)
GUICtrlCreateListViewItem("5|fb|alg 5", $ListView1)
GUICtrlCreateListViewItem("6|fb|alg 6", $ListView1)
GUICtrlCreateListViewItem("7|night|alg 7", $ListView1)
GUICtrlCreateListViewItem("8|night|alg 8", $ListView1)
$Button1 = GUICtrlCreateButton("Del Dup", 24, 168, 107, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $all[_GUICtrlListView_GetItemCount($ListView1)]

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            For $n = 0 to _GUICtrlListView_GetItemCount($ListView1) - 1
                $split_line = StringSplit(_GUICtrlListView_GetItemTextString($ListView1, $n),"|")
                $all[$n] = $split_line[2]
            Next
            _ArrayDupes($all,  1,  0)                ; delete duplicate array content

            _GUICtrlListView_DeleteAllItems($ListView1)            ; delete all of the ListView content

            For $n = 0 to Ubound($all) - 1                    ; display a new ListView content
                GUICtrlCreateListViewItem($n + 1 & "|" & $all[$n], $ListView1)
            Next

    EndSwitch
WEnd

Func _ArrayDupes(ByRef $arrItemsF, $iDelete = 0, $iDetails = 0)
    local $timerstamp1 = TimerInit()
    If @OSTYPE = "WIN32_WINDOWS"  Then Return 0
    If not IsArray($arrItemsF) then   Return 0
    Local $arrItems = $arrItemsF
    Local $i = 0, $k = 0, $objDictionary = ObjCreate("Scripting.Dictionary"), $arrItemsDupes[UBound($arrItems)]
    Local $objDictDupes = ObjCreate("Scripting.Dictionary")
    For $strItem In $arrItems
        If Not $objDictionary.Exists($strItem) Then
            $objDictionary.Add($strItem, $strItem)
        Else
            If $iDetails Then
                $arrItemsDupes[$k] = $strItem & "|Dupes|" & $i
            Else
                If Not $objDictDupes.Exists($strItem) Then $objDictDupes.Add($strItem, $strItem)
            EndIf
            $k += 1
        EndIf
        $i += 1
    Next
    ReDim $arrItems[$objDictionary.Count ]
    If $k = 0 Then ReDim $arrItemsDupes[1 ]
    If $k > 0 Then ReDim $arrItemsDupes[$k ]
    $i = 0
    If $iDelete Then
        For $strKey In $objDictionary.Keys
            $arrItems[$i] = $strKey
            $i += 1
        Next
        $arrItemsF = $arrItems ;array deleted dupes
    EndIf
    $i = 0
    If Not $iDetails Then
        For $strKey In $objDictDupes.Keys
            $arrItemsDupes[$i] = $strKey
            $i += 1
        Next
        If $i > 0 Then ReDim $arrItemsDupes[$i]
    EndIf
    Return $arrItemsDupes
EndFunc   ;==>_ArrayDupes
Link to comment
Share on other sites

  • Solution

Solved in a sample method :)

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 287, 442, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 24, 384, 75, 25)
$ListView = GUICtrlCreateListView("nr|text|save", 8, 16, 250, 326)
GUICtrlCreateListViewItem("1|one|one 1", $ListView)
GUICtrlCreateListViewItem("2|one|one 2", $ListView)
GUICtrlCreateListViewItem("3|test|one 3", $ListView)
GUICtrlCreateListViewItem("4|test|one 4", $ListView)
GUICtrlCreateListViewItem("5|fb|one 5", $ListView)
GUICtrlCreateListViewItem("6|fb|one 6", $ListView)
GUICtrlCreateListViewItem("7|night|one 7", $ListView)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            $count = _GUICtrlListView_GetItemCount($listview)
    For $x = 0 To $count - 1
        $Itemtxt1 = _GUICtrlListView_GetItemText($listview, $x, 1)
        For $y = _GUICtrlListView_GetItemCount($listview) - 1 To $x + 1 Step - 1
            $Itemtxt2 = _GUICtrlListView_GetItemText($listview, $y, 1)
            If StringUpper($Itemtxt1) = StringUpper($Itemtxt2) Then
                _GUICtrlListView_DeleteItem($listview, $y)
                $count -= 1
            EndIf
        Next
    Next
    For $i = 1 To _GUICtrlListView_GetItemCount($listview)
        _GUICtrlListView_SetItem($listview, $i+1, $i)
    Next

    MsgBox(64, "Info", "Delete All Duplicate !","",$Form1)

    EndSwitch
WEnd
Link to comment
Share on other sites

  • Moderators

incepator,

As no-one really has any idea why you are doing this, it is pretty difficult to suggest how you might do it faster. However, if you were to do the duplicate removal in an array before loading the remaining items into a ListView I imagine that you would get a significant increase in speed. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...