Jump to content

Need help to avoid redundant entries in TreeView


Recommended Posts

Hi,

I'm trying to fill a TreeView. Therefore I use the following code:

If _GUICtrlTreeView_FindItemEx($downloadTab0TV, $xItemValue[4], 0) = 0 Then _
                    $tvItem1 = GUICtrlCreateTreeViewItem($xItemValue[4], $downloadTab0TV)
                If _GUICtrlTreeView_FindItemEx($downloadTab0TV, $xItemValue[4] & "|" & _
                                                                $xItemValue[5], 0) = 0 Then _
                    $tvItem2 = GUICtrlCreateTreeViewItem($xItemValue[5], $tvItem1)
                If _GUICtrlTreeView_FindItemEx($downloadTab0TV, $xItemValue[4] & "|" & _
                                                                $xItemValue[5] & "|" & _
                                                                $xItemValue[2], 0) = 0 Then _
                    $tvItem3 = GUICtrlCreateTreeViewItem($xItemValue[2], $tvItem2)
                If _GUICtrlTreeView_FindItemEx($downloadTab0TV, $xItemValue[4] & "|" & _
                                                                $xItemValue[5] & "|" & _
                                                                $xItemValue[2] & "|" & _
                                                                $xItemValue[3], 0) = 0 Then _
                    $tvItem4 = GUICtrlCreateTreeViewItem($xItemValue[3], $tvItem3)

Unfortunately I can't avoid redundant entries, so the TreeView looks e. g. like this (affected are root and sub items):

[+] Microsoft

[+] x86

[+] x64

[+] Adobe

[+] Microsoft

[+] x86

[+] Server 2003

[+] Server 2003

[+] Server 2003

[+] Server 2003

Is there a way to avoid this?

Using _GUICtrlTreeView_FindItem/-Ex() (and its return code = TreeView-Item-Handle) doesn't really help.

Any help appreciated.

Greets,

-supersonic.

Edited by supersonic
Link to comment
Share on other sites

Thanks for your idea.

Sorting the array wouldn't help, because - later on - I will feed the TreeView with attributes from a XML file (_XMLDomWrapper.au3).

Attributes used in a XML file are often unsorted. I would like to get this working without a temp. array somewhere in between...

I don't think I am the only one with such a problem...

Maybe _ArraySort() and an _ArrayDelete() (if value [2]=[1] delete [2]) loop before building the tree is an option?

Edited by supersonic
Link to comment
Share on other sites

Don't think you'll get it sorted out without a temp array. Another idea would be

to copy the array to temp array,

sort it,

delete the dups

and afterwards during the treeview build do some checking if value is in temp array

then set counter in temp array +1

and only draw entry if counter is still 0.

This way you don't have to sort the original array and still can prevent dup entries in treeview.

Create a UDF of it and other's will participate too :), or maybe it's already done? search for dup removal in array / array remove dups or something like that...

Edited by KaFu
Link to comment
Share on other sites

Hmm... When using a temp. array I have to use a 2D array.

How to sort an 2D array. _ArraySort() supports only sorting a single column!?

Don't think you'll get it sorted out without a temp array. Another idea would be

to copy the array to temp array,

sort it,

delete the dups

and afterwards during the treeview build do some checking if value is in temp array

then set counter in temp array +1

and only draw entry if counter is still 0.

This way you don't have to sort the original array and still can prevent dup entries in treeview.

Create a UDF of it and other's will participate too :), or maybe it's already done? search for dup removal in array / array remove dups or something like that...

Link to comment
Share on other sites

Jesus, what a dirty coding style :) ...

#include <array.au3>

Local $array_org[6]
$array_org[0]= 'c'
$array_org[1]= 'a'
$array_org[2]= 'b'
$array_org[3]= 'a'
$array_org[4]= 'b'
$array_org[5]= 'd'

$array_temp = $array_org

_ArraySort($array_temp)

$array_size = UBound($array_temp) - 1
$i = 1
while $i < $array_size
    If $array_temp[$i] = $array_temp[$i-1] then
        _ArrayDelete($array_temp,$i)
        $array_size -= 1
    Else
        $i += 1
    EndIf
WEnd

local $array_temp2[UBound($array_temp)][2]

for $i = 0 to UBound($array_temp) -1
    $array_temp2[$i][0] = $array_temp[$i]
    $array_temp2[$i][1] = 0
Next

for $i = 0 to UBound($array_org) - 1
    if $i > UBound($array_org) - 1 then ExitLoop
    for $y = 0 to UBound($array_temp2) - 1
        if $array_org[$i] = $array_temp2[$y][0] Then
            if $array_temp2[$y][1] > 0 Then
                _ArrayDelete($array_org,$i)
                $i -= 1
                ExitLoop
            Else
                $array_temp2[$y][1] += 1
                ExitLoop
            EndIf
        EndIf
    Next
Next

_ArrayDisplay($array_org)
Edited by KaFu
Link to comment
Share on other sites

This - and the solution from the following post - works pretty well...

But how can I sort a 2D array with it... I can delete redundant entries,

because the order will totally screw up when filling the TreeView...

Please have a look at this array (copy/past from _ArrayDisplay()):

[0]|Microsoft Windows|XP|x86|German

[1]|Microsoft Windows|XP|x86|English_US

[2]|Microsoft Windows|General|x86|German

[3]|Microsoft Windows|General|x86|English_US

[4]|Microsoft Windows|General|x86|Global

[5]|Microsoft Windows|Vista|x64|Global

[6]|Microsoft Windows|Vista|x86|Global

[7]|Microsoft Windows|2000|x86|German

[8]|Microsoft Windows|2000|x86|English_US

[9]|Microsoft Office|2007|x64|Global

[10]|Microsoft Office|2007|x86|Global

[11]|Microsoft Office|2003|x86|German

[12]|Microsoft Office|2003|x86|English_US

[13]|Microsoft Office|2003|x86|Global

[14]|Microsoft Windows|Server 2003|x64|German

[15]|Microsoft Windows|Server 2003|x64|English_US

[16]|Microsoft Windows|Server 2003|x64|Global

[17]|Microsoft Windows|Server 2003|x86|German

[18]|Microsoft Windows|Server 2003|x86|English_US

I would like to sort column by column. After that i could

populate the TreeView by using the code mentioned above...

Sorry for begging you, please give me a clue...! :-|

Greets,

-supersonic.

Jesus, what a dirty coding style :) ...

#include <array.au3>

Local $array_org[6]
$array_org[0]= 'c'
$array_org[1]= 'a'
$array_org[2]= 'b'
$array_org[3]= 'a'
$array_org[4]= 'b'
$array_org[5]= 'd'

$array_temp = $array_org

_ArraySort($array_temp)

$array_size = UBound($array_temp) - 1
$i = 1
while $i < $array_size
    If $array_temp[$i] = $array_temp[$i-1] then
        _ArrayDelete($array_temp,$i)
        $array_size -= 1
    Else
        $i += 1
    EndIf
WEnd

local $array_temp2[UBound($array_temp)][2]

for $i = 0 to UBound($array_temp) -1
    $array_temp2[$i][0] = $array_temp[$i]
    $array_temp2[$i][1] = 0
Next

for $i = 0 to UBound($array_org) - 1
    if $i > UBound($array_org) - 1 then ExitLoop
    for $y = 0 to UBound($array_temp2) - 1
        if $array_org[$i] = $array_temp2[$y][0] Then
            if $array_temp2[$y][1] > 0 Then
                _ArrayDelete($array_org,$i)
                $i -= 1
                ExitLoop
            Else
                $array_temp2[$y][1] += 1
                ExitLoop
            EndIf
        EndIf
    Next
Next

_ArrayDisplay($array_org)
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...