supersonic Posted January 25, 2009 Share Posted January 25, 2009 (edited) 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 January 25, 2009 by supersonic Link to comment Share on other sites More sharing options...
KaFu Posted January 25, 2009 Share Posted January 25, 2009 Maybe _ArraySort() and an _ArrayDelete() (if value [2]=[1] delete [2]) loop before building the tree is an option? OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
supersonic Posted January 25, 2009 Author Share Posted January 25, 2009 (edited) 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 January 25, 2009 by supersonic Link to comment Share on other sites More sharing options...
KaFu Posted January 25, 2009 Share Posted January 25, 2009 (edited) 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 January 25, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
supersonic Posted January 25, 2009 Author Share Posted January 25, 2009 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 More sharing options...
KaFu Posted January 25, 2009 Share Posted January 25, 2009 (edited) Jesus, what a dirty coding style ... expandcollapse popup#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 January 25, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Spiff59 Posted January 25, 2009 Share Posted January 25, 2009 This works pretty well... #include <array.au3> Local $array_org[9] = ['c','c','a','b','a','b','a','d','d'] $Array_org = _ArrayUnique($array_org) _ArrayDisplay($array_org) Link to comment Share on other sites More sharing options...
KaFu Posted January 25, 2009 Share Posted January 25, 2009 There's always a smaller and smarter solution ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
supersonic Posted January 25, 2009 Author Share Posted January 25, 2009 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 ... expandcollapse popup#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 More sharing options...
Developers Jos Posted January 25, 2009 Developers Share Posted January 25, 2009 pretty sure I have seen this question before today..... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
supersonic Posted January 25, 2009 Author Share Posted January 25, 2009 You are right. I thought this should be an extra topic... Sorry for that.pretty sure I have seen this question before today..... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now