Jump to content

Why/how does my GuiCtrlList autosort/remove duplicates?


Recommended Posts

So I'm really confused.. I used the script below to read a .txt file into a Array.. I display that array, and everything is perfect. I then assign the array values into a GuiCtrlList using a simple For loop.. and the data seems to auto-remove duplicates and auto sort itself..? I don't understand why.. I attached the file I was using as well.

 

 

#include "UIAWrappers.au3"
#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>

HotKeySet("+!q", "_quit") ; Quit
Func _quit()
    Exit
EndFunc   ;==>_quit

Global $arrayofloaded, $filename
_FileReadToArray(@scriptdir & "\loadedfiles.txt", $arrayofloaded, 0)
If @error Then MsgBox(0, 0, @error)
Global $arrayfinal[Ubound($arrayofloaded)][2]
;~ _ArrayDisplay($arrayofloaded)
For $i = 0 To UBound($arrayofloaded) - 1
;~  ConsoleWrite("Starting with: " & $arrayofloaded[$i] & @CRLF)
    Local $sID = StringRegExp($arrayofloaded[$i], "\d\d\d\d\d\d\d\d.chw", 1)
    If @error Then MsgBox(0, 0, @error)
    $filename = $sID[0]
    $filename = StringRegExpReplace($filename, "\.chw", "") ; Remove the .cwh
    Local $realname = $arrayofloaded[$i]
    $realname = StringRegExpReplace($realname, "HPuv64.mtw", "") ; Remove the method name
    $realname = StringRegExpReplace($realname, "\d\d\d\d\d\d\d\d.chw", "") ; Remove the filename on IC
    $realname = StringRegExpReplace($realname, "<", "") ; Remove the < if file was open
    $realname = StringStripWS($realname, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES)
    ConsoleWrite("Filename " & $filename & " corresponds to the real value: " & $realname & @CRLF)

    $arrayfinal[$i][0] = $filename
    $arrayfinal[$i][1] = $realname
Next
_ArrayDisplay($arrayfinal, "IC2 Loader","", 64)

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("IC2 Loader", 302, 487, 192, 124)
$List1 = GUICtrlCreateList("", 0, 0, 60, 487)
$List2 = GUICtrlCreateList("", 60, 0, 241, 487)

For $i = 0 To UBound($arrayofloaded) - 1
    GUICtrlSetData($List1, $arrayfinal[$i][0])
    GUICtrlSetData($List2, $arrayfinal[$i][1])
Next

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

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

    EndSwitch
WEnd

 

loadedfiles.txt

Link to post
Share on other sites

@BatMan22

When you create the List, by default, it has the $LBS_SORT style set, so, the sorting of your list is an expected behaviour having that style.

By the way, you are making way too many (and unnecessary) steps to have all the information you are retrieving from your file; one of many, you could read your file with the @TAB separator char.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to post
Share on other sites
  • Moderators

BatMan22,

The default style for ListBoxes includes the $LBS_SORT style - hence sorting is default. if you want to have the ListBox unsorted, then you need to explicitly define the styles and omit the "sort" one:

$List1 = GUICtrlCreateList("", 0, 0, 60, 387, BitOr($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY))
$List2 = GUICtrlCreateList("", 60, 0, 241, 387, BitOr($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY))

See the Setting Styles tutorial in the Wiki for more details.

Using GUICtrlSetData when loading a ListBox sets any "double" values as the default - as explained in the Help file:

Quote

For Combo or List control :
If the "data" corresponds to an already existing entry it is set as the default.

You can always use _GUICtrlListBox_AddString to avoid this problem:

;GUICtrlSetData($List1, $arrayfinal[$i][0])
_GUICtrlListBox_AddString($List1, $arrayfinal[$i][0])
;GUICtrlSetData($List2, $arrayfinal[$i][1])
_GUICtrlListBox_AddString($List2, $arrayfinal[$i][1])

Please ask if you have any further questions.

M23

Edit: late, but more complete!

Edited by Melba23

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 post
Share on other sites

Oops. Sorry and thank you guys! Didn't know that lists were sorted by default or that double values were set to default. 

Fixed code: 

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("IC2 Loader", 302, 487, 192, 124)
$List1 = GUICtrlCreateList("", 0, 0, 60, 487, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY))
$List2 = GUICtrlCreateList("", 60, 0, 241, 487, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY))

For $i = 0 To UBound($arrayofloaded) - 1
;~  GUICtrlSetData($List1, $arrayfinal[$i][0])
;~  GUICtrlSetData($List2, $arrayfinal[$i][1])
    _GUICtrlListBox_AddString($List1, $arrayfinal[$i][0])
    _GUICtrlListBox_AddString($List2, $arrayfinal[$i][1])
Next

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

 

Link to post
Share on other sites

You know @Nine, if someone were to go through my programming and were to optimize everything and use 'smarter' coding, I bet you my programs would reduce by like ~85% as far as number of lines. I'm 35 and learning to program and wish I had started a long long time ago lol. That being said, thanks, I know something new now :)

Link to post
Share on other sites
1 minute ago, BatMan22 said:

You know @Nine, if someone were to go through my programming and were to optimize everything and use 'smarter' coding, I bet you my programs would reduce by like ~85% as far as number of lines. I'm 35 and learning to program and wish I had started a long long time ago lol. That being said, thanks, I know something new now :)

I know you'll go far in programming, you are the BatMan after all :lol:

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...