Jump to content

GUI list sort option and


Recommended Posts

Hi!

 

My list view sorts funny, it goes:

  • 1
  • 12
  • 134
  • 2
  • 256
  • 248
  • 3
  • 648
  • 8

And so fourth, instead of sorting it like common folks would! I can imagine I could fix this by adding zeroes in front to match the highest numbers string length (like 001). But I'd like it to instead sort it like any grade A maths teacher would:

  • 1
  • 2
  • 3
  • 10
  • 15
  • 20

Any ideas? Also, how hard would it be to make a selected item in the list copyable. Just instead of straight copy that line, instead have it activate a script to use ClipPut() to make the user copy a certain string based on what list object they selected? This is a episode folder scanner, so if I copied missing episode 9. Instead of "Episode 9" being in clipboard, have "[something, something] & 9" in clipboard.

Here is my koda script so you can see my GUI:

#Region ### START Koda GUI section ### Form=
$LesGUI = GUICreate("Linas Episode Scanner", 274, 242, 192, 124, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$IDirectory = GUICtrlCreateInput("", 8, 8, 225, 21)
$browse = GUICtrlCreateButton("...", 240, 8, 30, 21)
$Season = GUICtrlCreateLabel("Season #", 8, 56, 50, 17, $SS_CENTER)
$ISeason = GUICtrlCreateInput("Null", 8, 80, 50, 21)
$EpisodeS = GUICtrlCreateLabel("Episode Start", 103, 56, 67, 17, $SS_CENTER)
$EpisodeE = GUICtrlCreateLabel("Episode End", 200, 56, 64, 17)
$IEpisodeS = GUICtrlCreateInput("Null", 113, 80, 50, 21)
$IEpisodeE = GUICtrlCreateInput("Null", 200, 80, 65, 21)
$BExit = GUICtrlCreateButton("Exit", 192, 208, 75, 25)
$BRefresh = GUICtrlCreateButton("Refresh", 192, 176, 75, 25)
$BTop = GUICtrlCreateButton("Stay On Top", 192, 144, 75, 25)
$LEpisodesMissing = GUICtrlCreateLabel("Missing Episodes:", 8, 112, 88, 17)
$ListMissing = GUICtrlCreateList("", 8, 136, 153, 97)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

 

Link to comment
Share on other sites

Just messing around, not sure if itst a solution any better than what you had or if it even works in your situation but its a proof of concept :)

 

#Include <Array.au3>


Local $aTest[8] = ["1", "2", "3", "12", "134", "14", "256", "8"]
Local $aTest2[8]

For $i = 0 to UBound($aTest) -1
    $aTest2[$i] = Hex($aTest[$i])
Next


_ArrayDisplay($aTest)
_ArrayDisplay($aTest2)

_ArraySort($aTest2)


For $i = 0 to UBound($aTest) -1
    $aTest[$i] = Dec($aTest2[$i])
Next

_ArrayDisplay($aTest)
_ArrayDisplay($aTest2)

 

Link to comment
Share on other sites

  • Moderators

Sodori,

By default the list control has the $LB_SORT style which forces a sort of the items and also assumes that they are in string format, which leads to the rather unexpected order you see. So you need to remove that style from the list when you create it and sort the values as numbers before adding them to the list:

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>
#include <Array.au3>

; Array of values as strings
Global $aList_String[8] = ["1", "2", "3", "12", "134", "14", "256", "8"]
; And sorted as strings
_ArraySort($aList_String)

; Array of values as numbers
Global $aList_Number[8] = [1, 2, 3, 12, 134, 14, 256, 8]
; And sorted as numbers
_ArraySort($aList_Number)

$hGUI = GUICreate("Test", 500, 500)

; Create lists without the sort style
$cList_String = GUICtrlCreateList("", 10, 10, 230, 300, BitOr($WS_BORDER, $WS_VSCROLL))
$cList_Number = GUICtrlCreateList("", 260, 10, 230, 300, BitOr($WS_BORDER, $WS_VSCROLL))

; Add items to the lists
For $i = 0 To 7
    GUICtrlSetData($cList_String, $aList_String[$i])
    GUICtrlSetData($cList_Number, $aList_Number[$i])
Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

All clear?

M23

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

Much thanks Melba23! How easy do you think it would be for a trigger event upon copying a single item (i.e. selecting a single variable and pressing CTRL+C, with said variable included with the trigger)?

Link to comment
Share on other sites

  • Moderators

Sodori,

I would use a Accelerator key like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <WinAPI.au3>

; Array of values as strings
Global $aList_String[8] = ["1", "2", "3", "12", "134", "14", "256", "8"]
; And sorted as strings
_ArraySort($aList_String)

; Array of values as numbers
Global $aList_Number[8] = [1, 2, 3, 12, 134, 14, 256, 8]
; And sorted as numbers
_ArraySort($aList_Number)

$hGUI = GUICreate("Test", 500, 500)

; Create lists without the sort style
$cList_String = GUICtrlCreateList("", 10, 10, 230, 300, BitOr($WS_BORDER, $WS_VSCROLL))
$cList_Number = GUICtrlCreateList("", 260, 10, 230, 300, BitOr($WS_BORDER, $WS_VSCROLL))

; Add items to the lists
For $i = 0 To 7
    GUICtrlSetData($cList_String, $aList_String[$i])
    GUICtrlSetData($cList_Number, $aList_Number[$i])
Next

$cDummy = GUICtrlCreateDummy()

GUISetState()

Local $aAccelKeys[1][2] = [["^c", $cDummy]]
GUISetAccelerators($aAccelKeys)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cDummy

            Switch _WinAPI_GetFocus()
                Case GUICtrlGetHandle($cList_String)
                    ConsoleWrite(GUICtrlRead($cList_String) & @CRLF)
                Case GUICtrlGetHandle($cList_Number)
                    ConsoleWrite(GUICtrlRead($cList_Number) & @CRLF)
            EndSwitch

    EndSwitch
WEnd

M23

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

  • Moderators

Sodori,

Glad I could help.

M23

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