Sign in to follow this  
Followers 0
tommeke228

Sorting a listview

8 posts in this topic

Hi there

Here's a picture of my listview loaded in with FileFindFirstFile

 

and here with _FileListToArray

 

How can i make that it sorts perfectly from 1 till 12 ?

Putting numbers in the filename doesnt work, it doesn't work without it... pff :P

is there an easy solution ?

grtz

Tom

post-34879-0-57909200-1420817520.png

post-34879-0-20729700-1420817528_thumb.p

Share this post


Link to post
Share on other sites



tommeke228,

 

is there an easy solution ?

In short - no. As this recent thread showed. :(>

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

pff thanks :P

gona search a solution because it needs to be fixed ;p (will post it then)

grtz

tom

Share this post


Link to post
Share on other sites

tommeke228,

If these filenames are created by you, then forcing the leading number into a fixed format with leading zeroes will work. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You can re-dim the array to add a second dimention...use a regexp to grab the leading numbers, and convert them to integers...then sort by that new column...edit: repopulate back to the 1d array.

#include <Array.au3>
Local $a[3]=["1 something", "11 something2", "2 something3"]
_ArrayDisplay($a)

; since the redim doesn't work when changing dimentions, create a new one...quicker
Local $a2[UBound($a)][2]
For $i = 0 To UBound($a2)-1
    $a2[$i][0] = $a[$i]
    $a2[$i][1] = Number(StringRegExpReplace($a[$i],"(\d+)(.*)","\1"))
Next

_ArraySort($a2,0,0,0,1)
For $i = 0 To UBound($a)-1
    $a[$i] = $a2[$i][0]
Next
$a2 = ""

_ArrayDisplay($a)
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

As Melba said, leading zeros with StringFormat (I usually use 6) solves the issue nicely for future issues.

This situation is easily fixed though, just using converting to int().

IMO, this is not a cure all though, doesn't take care of numbers throughout the string.

#include <Array.au3>

Global $gaOrignal[] = [ _
    "1 Monday 5 January 2015_6u_7u", "10 Tuesday 6 January 2015_4-5", _
    "11 Tuesday 6 January 2015_17u15-18u15", "12 Wednesday 7 January 2015_6u15-7u15", _
    "2 Monday 5 January 2015_7u15-9u15", "3 Monday 5 January 2015_9u30-12u00", _
    "4 Monday 5 January 2015_12u30-16u00", "5 Monday 5 January 2015_16u-17u", _
    "6 Tuesday 6 January 2015_6u15-7u15", "7 Tuesday 6 January 2015_7u15-9u15", _
    "8 Tuesday 6 January 2015_9u30-12", "9 Tuesday 6 January 2015_12u30-17u15"]

_ArrayDisplay($gaOrignal)
_mySimple1DArrSortSolution($gaOrignal)
_ArrayDisplay($gaOrignal)


Func _mySimple1DArrSortSolution(ByRef $aArr, $iDesc = 0, $iStart = 0, $iEnd = 0)

    If Not IsArray($aArr) Then Return SetError(1, 0, 0)
    If UBound($aArr, 2) Then Return SetError(2, 0, 0)

    Local $iUB = UBound($aArr)
    If $iEnd < $iStart Or $iEnd > ($iUB - 1) Then Return SetError(3, 0, 0)
    $iEnd = (IsKeyword($iEnd) Or $iEnd < 1) ? $iUB - 1 : $iEnd

    Local $aTmp[$iUB][2]
    For $i = $iStart To $iEnd
        $aTmp[$i][0] = $aArr[$i]
        $aTmp[$i][1] = Int($aArr[$i])
    Next

    _ArraySort($aTmp, $iDesc, $iStart, $iEnd, 1)

    For $i = $iStart To $iEnd
        $aArr[$i] = $aTmp[$i][0]
    Next

EndFunc

Edit:

Oops, didn't see jdelaney posted.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Almost exactly the same technique...I just used a regexp to grab the first digits, instead of grabbing all of them.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

thankyou so much guys !!!! :thumbsup: :thumbsup:

post-34879-0-35115200-1420885267.png

Edited by tommeke228

Share this post


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
Sign in to follow this  
Followers 0