Jump to content

ListView control - rename duplicates


Furek86
 Share

Recommended Posts

Hi guys,

I was wondering if there was a function, or someone has a UDF, to rename duplicated values in a listview?

For instance

1. STST

2. STST

Script would rename these values to

1. STST

2. STST_

and so on...like

1. STST

2. STST

3. STST

Script would rename to:

1. STST

2. STST_

3. STST__

I have tried sorting the listview items and then:

For $i = 0 to _GUICtrlListView_GetItemCount($lstFiles)

if _GUICtrlListView_GetItemText($lstFiles,$i) = _GUICtrlListView_GetItemText($lstFiles,$i-1) Then

_GUICtrlListView_SetItemText($lstFiles,$i,_GUICtrlListView_GetItemText($lstFiles,$i) & "_")

EndIf

next

But this will only apply if I have 2 duplicated items and I was wondering if it maybe could be done for N duplicated items.

Any help is appreciated.

Link to comment
Share on other sites

You might employ some of the Assign/IsDeclared trickery that Yashied used in his _ArrayUniqueFast example.

Something like this (modified to update your listview, rather than an array):

#include <Array.au3>

Global $aArray[10] = ["abc", "xyz", "abc", "xxx", "xyz", "abc", "ccc", "xyz", "abc", "abc"]

For $x = 0 to 9
    $suffix = ""
    While IsDeclared("$$" & $aArray[$x] & $suffix)
        $suffix &= "_"
    WEnd
    $aArray[$x] &= $suffix
    Assign("$$" & $aArray[$x], "")
Next

_ArrayDisplay($aArray)
Link to comment
Share on other sites

Thank you :) I modified my code as you said and it looks like below:

For $x = 0 to _GUICtrlListView_GetItemCount($lstFiles)
    $suffix = ""
$item = _GUICtrlListView_GetItemText($lstFiles,$x)
    While IsDeclared("$$" & $item & $suffix)
        $suffix &= "_"
    WEnd
    $item &= $suffix
_GUICtrlListView_SetItemText($lstFiles,$x,$item)
    Assign("$$" & $item, "")
Next

and it works perfectly ;)

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