Sign in to follow this  
Followers 0
Reinhardt1julian

Sort Listview Name / Surname

18 posts in this topic

I have a list view (first two colums are Name and Surname). Now I want to sort the items by alphabet. It should sort the names from A to Z and if the Name is teh shame it should sort it by the surname, too.

I know about the _GUICtrlListView_SimpleSort() Function, but that only sorts one column.

My problem is, that I want to save a value with the number in the list view (first is number one, second is number two...) in a file so when I need to retreive that value I search for the number of the item in the file.

Thank you!

Share this post


Link to post
Share on other sites

Reinhardt1julian,

I posted this UDF a while ago which sorts exactly as you require. You would need to extract the contents of the ListView into an array, sort the array with the UDF and then reload the array into the ListView - which is a lot easier than it sounds, believe me! ;)

Let me know if I can help you get it all working. :)

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

#3 ·  Posted (edited)

@Melba23

Since I have not worked with Arraylists before I am not quite understanding your code. And I don't know what $aSortData needs to be. And for me it has a Syntax error (in the AMCS_Ex.au3) at line 20 ("Global $aSortData[][] = [ _") Character 19

Edited by Reinhardt1julian

Share this post


Link to post
Share on other sites

Reinhardt1julian,

I will work up an example for you so that you can see it in action. :)

And you get the error because you need the Beta to run that syntax. ;)

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

Reinhardt1julian,

Here you go: ;)

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include "ArrayMultiColSort.au3"

#include <Array.au3>

Global $aList[8][2] = [[7, 0], _
        ["Tom", "Cliffe"], _
        ["Dick", "Harries"], _
        ["Harry", "Thompson"], _
        ["Tom", "Williams"], _
        ["Dick", "Webb"], _
        ["Harry", "Manning"], _
        ["Tom", "Payne"]]

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

$cLV = GUICtrlCreateListView("Forename       |Name            ", 10, 10, 400, 300)
_LoadArrayToLV($cLV, $aList, 1)

$cSort = GUICtrlCreateButton("Sort", 10, 350, 80, 30)

GUISetState()

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

Func _Sort()

    ; Read ListView content into an array
    Local $aArray = _ReadLVToArray($cLV)

    _ArrayDisplay($aArray, "Before sort")

    ; Multisort the array - both columns "Ascending"
    Local $aSortData[2][2] = [[0, 0], [1, 0]]
    _ArrayMultiColSort($aArray, $aSortData)

    _ArrayDisplay($aArray, "After sort")

    ; Now reload the array into the ListView
    _LoadArrayToLV($cLV, $aArray)

EndFunc

Func _LoadArrayToLV($cLV, $aArray, $iStart = 0)

    ; Delete current items
    _GUICtrlListView_DeleteAllItems($cLV)

    ; Load from array
    For $i = 0 + $iStart To UBound($aArray) - 1
        GUICtrlCreateListViewItem($aArray[$i][0] & "|" & $aArray[$i][1], $cLV)
    Next

EndFunc

Func _ReadLVToArray($cLV, $iStart = 0)

    Local $aLVArray = "", $aRow

    ; Get ListView row count
    Local $iRows = _GUICtrlListView_GetItemCount($cLV)
    ; Check for empty ListView with no count
    If $iRows + $iStart <> 0 Then
        ; Get ListView column count
        Local $iCols = _GUICtrlListView_GetColumnCount($cLV)
        ; Create 2D array to hold ListView content and add count - count overwritten if not needed
        Local $aLVArray[$iRows + $iStart][$iCols] = [[$iRows]]
        ; Read ListView content into array
        For $i = 0 To $iRows - 1
            ; Read the row content
            $aRow = _GUICtrlListView_GetItemTextArray($cLV, $i)
            For $j = 1 To $aRow[0]
                ; Add to the ListView content array
                $aLVArray[$i + $iStart][$j - 1] = $aRow[$j]
            Next
        Next
    EndIf
    ; Return array or empty string
    Return $aLVArray

EndFunc
Please ask if you any questions. :)

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

Thank you so much! Is it possible to copy it 1:1 (i know i have to change some variables) or do i have to modify some things? Doesn't look like it.

Share this post


Link to post
Share on other sites

Reinhardt1julian,

You should be able to paste those functions straight into your script. But you know where I am if you run into any problems. ;)

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

Oh, does this also work if there are more colums than the two? But it should only use the first two :D It looks like it, but I want to make sure... And it's complicated to test right now, because first i have to edity my whole aready made script

Share this post


Link to post
Share on other sites

Reinhardt1julian'

 

does this also work if there are more colums than the two?

It certainly does - just increase the number of elements in the array. This is explained in the UDF header and shown in the UDF example - which is why I wrote them. ;)

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

Yeah, but it should ignore those coulumn in the sorting process. Just sort it using the first two colums and ignore the rest, and put them back sortet into the arraylist. From the UDF example i understood that it uses all columns to sort it.

Share this post


Link to post
Share on other sites

Reinhardt1julian,

No, the [#][0] element defines the column to sort - so the example I gave you would only sort columns 0 and 1 even if there were more than 2. Using this syntax would sort columns 3 and 4 while ignoring 0 and 1:

Local $aSortData[2][2] = [[3, 0], [4, 0]]
Clearer now? :)

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

#12 ·  Posted (edited)

Mostly.

So it needs to be

Local $aSortData[6][6] = [[0, 0], [1, 0]]

If it has 6 columns but should only sort the first two?

BTW, thanks for sacrificing so much time for me :D I appreciate that!

Edited by Reinhardt1julian

Share this post


Link to post
Share on other sites

Reinhardt1julian,

No, just this: :)

Local $aSortData[2][2] = [[0, 0], [1, 0]]
You really need to learn about 2D arrays! ;)

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

Yeah I do....

But now it takes the LiswViewItem for example

Smith|John|Info|07700|900583|B2 4DB
|Birmingham

And puts it back in as

Smith|John

Share this post


Link to post
Share on other sites

Reinhardt1julian,

Please post the code you have and I will see how we can sort it. :)

Remember you did not mention anything about 6 columns when you started this thread - I solved the problem you stated, so moving the goalposts mid-thread is very likely to throw up problems. ;)

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

#16 ·  Posted (edited)

I made an example code:

#include <ListViewConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <WindowsConstants.au3>
    $Form5 = GUICreate("Test", 674, 469, -1, -1)
    $List1 = GUICtrlCreateListView("Name|Surename|Info|Area Code|Telephone|Postal code|City", 8, 32, 353, 383, -1, BitOR($WS_EX_ACCEPTFILES,$LVS_EX_FULLROWSELECT))
    $Button4 = GUICtrlCreateButton("Sort", 368, 232, 75, 25)
    GUISetState(@SW_SHOW)
    GUICtrlCreateListViewItem("Parker|Peter|This is info|3418|2154626|B2 4DB|Birmingham", $List1)
    GUICtrlCreateListViewItem("Louis|Louis|Is a person|4583|7952461|B2 4DB|Birmingham", $List1)
    GUICtrlCreateListViewItem("Grey|Christian|Is a random name|3419|794413154|B2 4DB|Birmingham", $List1)
    GUICtrlCreateListViewItem("Williams|John|Is a common name|8465|35415164|B2 4DB|Birmingham", $List1)
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Button4
                _Sort($List1)
            EndSwitch
        WEnd


Func _Sort($listview)
    ; Read ListView content into an array
    Local $aArray = _ReadLVToArray($listview)
    ; Multisort the array - both columns "Ascending"
    Local $aSortData[2][2] = [[0, 0], [1, 0]]
    _ArrayMultiColSort($aArray, $aSortData)
    ; Now reload the array into the ListView
    _LoadArrayToLV($listview, $aArray)
EndFunc
Func _LoadArrayToLV($cLV, $aArray, $iStart = 0)
    ; Delete current items
    _GUICtrlListView_DeleteAllItems($cLV)
    ; Load from array
    For $i = 0 + $iStart To UBound($aArray) - 1
        GUICtrlCreateListViewItem($aArray[$i][0] & "|" & $aArray[$i][1], $cLV)
    Next
EndFunc
Func _ReadLVToArray($cLV, $iStart = 0)
    Local $aLVArray = "", $aRow
    ; Get ListView row count
    Local $iRows = _GUICtrlListView_GetItemCount($cLV)
    ; Check for empty ListView with no count
    If $iRows + $iStart <> 0 Then
        ; Get ListView column count
        Local $iCols = _GUICtrlListView_GetColumnCount($cLV)
        ; Create 2D array to hold ListView content and add count - count overwritten if not needed
        Local $aLVArray[$iRows + $iStart][$iCols] = [[$iRows]]
        ; Read ListView content into array
        For $i = 0 To $iRows - 1
            ; Read the row content
            $aRow = _GUICtrlListView_GetItemTextArray($cLV, $i)
            For $j = 1 To $aRow[0]
                ; Add to the ListView content array
                $aLVArray[$i + $iStart][$j - 1] = $aRow[$j]
            Next
        Next
    EndIf
    ; Return array or empty string
    Return $aLVArray
EndFunc
Func _ArrayMultiColSort(ByRef $aArray, $aSortData, $iStart = 0, $iEnd = 0)
    If UBound($aArray, 2) = 0 Then
        Return SetError(1, 1, "")
    EndIf
    ; 2D sort data
    If UBound($aSortData, 2) <> 2 Then
        Return SetError(1, 2, "")
    EndIf
    If UBound($aSortData) > UBound($aArray) Then
        Return SetError(1, 3)
    EndIf
    ; Start element
    If $iStart < 0 Then
        $iStart = 0
    EndIf
    If $iStart >= UBound($aArray) - 1 Then
        Return SetError(1, 4, "")
    EndIf
    ; End element
    If $iEnd <= 0 Or $iEnd >= UBound($aArray) - 1 Then
        $iEnd = UBound($aArray) - 1
    EndIf
    ; Sanity check
    If $iEnd <= $iStart Then
        Return SetError(1, 5, "")
    EndIf
    Local $iCurrCol, $iChunk_Start, $iMatchCol
    ; Sort first column
    __AMCS_SortChunk($aArray, $aSortData, 0, $aSortData[0][0], $iStart, $iEnd)
    If @error Then
        Return SetError(2, @extended, "")
    EndIf
    ; Now sort within other columns
    For $iSortData_Row = 1 To UBound($aSortData) - 1
        ; Determine column to sort
        $iCurrCol = $aSortData[$iSortData_Row][0]
        ; Create arrays to hold data from previous columns
        Local $aBaseValue[$iSortData_Row]
        ; Set base values
        For $i = 0 To $iSortData_Row - 1
            $aBaseValue[$i] = $aArray[$iStart][$aSortData[$i][0]]
        Next
        ; Set start of this chunk
        $iChunk_Start = $iStart
        ; Now work down through array
        For $iRow = $iStart + 1 To $iEnd
            ; Match each column
            For $k = 0 To $iSortData_Row - 1
                $iMatchCol = $aSortData[$k][0]
                ; See if value in each has changed
                If $aArray[$iRow][$iMatchCol] <> $aBaseValue[$k] Then
                    ; If so and row has advanced
                    If $iChunk_Start < $iRow - 1 Then
                        ; Sort this chunk
                        __AMCS_SortChunk($aArray, $aSortData, $iSortData_Row, $iCurrCol, $iChunk_Start, $iRow - 1)
                        If @error Then
                            Return SetError(2, @extended, "")
                        EndIf
                    EndIf
                    ; Set new base value
                    $aBaseValue[$k] = $aArray[$iRow][$iMatchCol]
                    ; Set new chunk start
                    $iChunk_Start = $iRow
                EndIf
            Next
        Next
        ; Sort final section
        If $iChunk_Start < $iRow - 1 Then
            __AMCS_SortChunk($aArray, $aSortData, $iSortData_Row, $iCurrCol, $iChunk_Start, $iRow - 1)
            If @error Then
                Return SetError(2, @extended, "")
            EndIf
        EndIf
    Next
EndFunc   ;==>_ArrayMultiColSort
Func __AMCS_SortChunk(ByRef $aArray, $aSortData, $iRow, $iColumn, $iChunkStart, $iChunkEnd)
    Local $aSortOrder
    ; Set default sort direction
    Local $iSortDirn = 1
    ; Need to prefix elements?
    If IsString($aSortData[$iRow][1]) Then
        ; Split elements
        $aSortOrder = StringSplit($aSortData[$iRow][1], ",")
        If @error Then
            Return SetError(1, 1, "")
        EndIf
        ; Add prefix to each element
        For $i = $iChunkStart To $iChunkEnd
            For $j = 1 To $aSortOrder[0]
                If $aArray[$i][$iColumn] = $aSortOrder[$j] Then
                    $aArray[$i][$iColumn] = StringFormat("%02i-", $j) & $aArray[$i][$iColumn]
                    ExitLoop
                EndIf
            Next
            ; Deal with anything that does not match
            If $j > $aSortOrder[0] Then
                $aArray[$i][$iColumn] = StringFormat("%02i-", $j) & $aArray[$i][$iColumn]
            EndIf
        Next
    Else
        Switch $aSortData[$iRow][1]
            Case 0, 1
                ; Set required sort direction if no list
                If $aSortData[$iRow][1] Then
                    $iSortDirn = -1
                Else
                    $iSortDirn = 1
                EndIf
            Case Else
                Return SetError(1, 2, "")
        EndSwitch
    EndIf
    ; Sort the chunk
    Local $iSubMax = UBound($aArray, 2) - 1
    __ArrayQuickSort2D($aArray, $iSortDirn, $iChunkStart, $iChunkEnd, $iColumn, $iSubMax)
    ; Remove any prefixes
    If IsString($aSortData[$iRow][1]) Then
        For $i = $iChunkStart To $iChunkEnd
            $aArray[$i][$iColumn] = StringTrimLeft($aArray[$i][$iColumn], 3)
        Next
    EndIf
EndFunc   ;==>__AMCS_SortChunk
Edited by Reinhardt1julian

Share this post


Link to post
Share on other sites

Reinhardt1julian,

That was easy to fix: :)

#include <ListViewConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

$Form5 = GUICreate("Test", 674, 469, -1, -1)
$List1 = GUICtrlCreateListView("Name|Surename|Info|Area Code|Telephone|Postal code|City", 8, 32, 353, 383, -1, BitOR($WS_EX_ACCEPTFILES, $LVS_EX_FULLROWSELECT))
$Button4 = GUICtrlCreateButton("Sort", 368, 232, 75, 25)
GUISetState(@SW_SHOW)
GUICtrlCreateListViewItem("Parker|Peter|This is info|3418|2154626|B2 4DB|Birmingham", $List1)
GUICtrlCreateListViewItem("Louis|Louis|Is a person|4583|7952461|B2 4DB|Birmingham", $List1)
GUICtrlCreateListViewItem("Grey|Christian|Is a random name|3419|794413154|B2 4DB|Birmingham", $List1)
GUICtrlCreateListViewItem("Williams|John|Is a common name|8465|35415164|B2 4DB|Birmingham", $List1)
GUICtrlCreateListViewItem("Parker|John|Is a common name|8465|35415164|B2 4DB|Birmingham", $List1)
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button4
            _Sort($List1)
    EndSwitch
WEnd


Func _Sort($listview)
    ; Read ListView content into an array
    Local $aArray = _ReadLVToArray($listview)
    ; Multisort the array - both columns "Ascending"
    Local $aSortData[2][2] = [[0, 0],[1, 0]]
    _ArrayMultiColSort($aArray, $aSortData)
    ; Now reload the array into the ListView
    _LoadArrayToLV($listview, $aArray)
EndFunc   ;==>_Sort
Func _LoadArrayToLV($cLV, $aArray, $iStart = 0)
    ; Delete current items
    _GUICtrlListView_DeleteAllItems($cLV)
    ; Load from array
    For $i = 0 + $iStart To UBound($aArray) - 1
        $sItem = ""
        For $j = 0 To UBound($aArray, 2) - 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            $sItem &= $aArray[$i][$j] & "|"
        Next
        $sItem = StringTrimRight($sItem, 1)
        GUICtrlCreateListViewItem($sItem, $cLV)
    Next
EndFunc   ;==>_LoadArrayToLV
Func _ReadLVToArray($cLV, $iStart = 0)
    Local $aLVArray = "", $aRow
    ; Get ListView row count
    Local $iRows = _GUICtrlListView_GetItemCount($cLV)
    ; Check for empty ListView with no count
    If $iRows + $iStart <> 0 Then
        ; Get ListView column count
        Local $iCols = _GUICtrlListView_GetColumnCount($cLV)
        ; Create 2D array to hold ListView content and add count - count overwritten if not needed
        Local $aLVArray[$iRows + $iStart][$iCols] = [[$iRows]]
        ; Read ListView content into array
        For $i = 0 To $iRows - 1
            ; Read the row content
            $aRow = _GUICtrlListView_GetItemTextArray($cLV, $i)
            For $j = 1 To $aRow[0]
                ; Add to the ListView content array
                $aLVArray[$i + $iStart][$j - 1] = $aRow[$j]
            Next
        Next
    EndIf
    ; Return array or empty string
    Return $aLVArray
EndFunc   ;==>_ReadLVToArray
Func _ArrayMultiColSort(ByRef $aArray, $aSortData, $iStart = 0, $iEnd = 0)
    If UBound($aArray, 2) = 0 Then
        Return SetError(1, 1, "")
    EndIf
    ; 2D sort data
    If UBound($aSortData, 2) <> 2 Then
        Return SetError(1, 2, "")
    EndIf
    If UBound($aSortData) > UBound($aArray) Then
        Return SetError(1, 3)
    EndIf
    ; Start element
    If $iStart < 0 Then
        $iStart = 0
    EndIf
    If $iStart >= UBound($aArray) - 1 Then
        Return SetError(1, 4, "")
    EndIf
    ; End element
    If $iEnd <= 0 Or $iEnd >= UBound($aArray) - 1 Then
        $iEnd = UBound($aArray) - 1
    EndIf
    ; Sanity check
    If $iEnd <= $iStart Then
        Return SetError(1, 5, "")
    EndIf
    Local $iCurrCol, $iChunk_Start, $iMatchCol
    ; Sort first column
    __AMCS_SortChunk($aArray, $aSortData, 0, $aSortData[0][0], $iStart, $iEnd)
    If @error Then
        Return SetError(2, @extended, "")
    EndIf
    ; Now sort within other columns
    For $iSortData_Row = 1 To UBound($aSortData) - 1
        ; Determine column to sort
        $iCurrCol = $aSortData[$iSortData_Row][0]
        ; Create arrays to hold data from previous columns
        Local $aBaseValue[$iSortData_Row]
        ; Set base values
        For $i = 0 To $iSortData_Row - 1
            $aBaseValue[$i] = $aArray[$iStart][$aSortData[$i][0]]
        Next
        ; Set start of this chunk
        $iChunk_Start = $iStart
        ; Now work down through array
        For $iRow = $iStart + 1 To $iEnd
            ; Match each column
            For $k = 0 To $iSortData_Row - 1
                $iMatchCol = $aSortData[$k][0]
                ; See if value in each has changed
                If $aArray[$iRow][$iMatchCol] <> $aBaseValue[$k] Then
                    ; If so and row has advanced
                    If $iChunk_Start < $iRow - 1 Then
                        ; Sort this chunk
                        __AMCS_SortChunk($aArray, $aSortData, $iSortData_Row, $iCurrCol, $iChunk_Start, $iRow - 1)
                        If @error Then
                            Return SetError(2, @extended, "")
                        EndIf
                    EndIf
                    ; Set new base value
                    $aBaseValue[$k] = $aArray[$iRow][$iMatchCol]
                    ; Set new chunk start
                    $iChunk_Start = $iRow
                EndIf
            Next
        Next
        ; Sort final section
        If $iChunk_Start < $iRow - 1 Then
            __AMCS_SortChunk($aArray, $aSortData, $iSortData_Row, $iCurrCol, $iChunk_Start, $iRow - 1)
            If @error Then
                Return SetError(2, @extended, "")
            EndIf
        EndIf
    Next
EndFunc   ;==>_ArrayMultiColSort
Func __AMCS_SortChunk(ByRef $aArray, $aSortData, $iRow, $iColumn, $iChunkStart, $iChunkEnd)
    Local $aSortOrder
    ; Set default sort direction
    Local $iSortDirn = 1
    ; Need to prefix elements?
    If IsString($aSortData[$iRow][1]) Then
        ; Split elements
        $aSortOrder = StringSplit($aSortData[$iRow][1], ",")
        If @error Then
            Return SetError(1, 1, "")
        EndIf
        ; Add prefix to each element
        For $i = $iChunkStart To $iChunkEnd
            For $j = 1 To $aSortOrder[0]
                If $aArray[$i][$iColumn] = $aSortOrder[$j] Then
                    $aArray[$i][$iColumn] = StringFormat("%02i-", $j) & $aArray[$i][$iColumn]
                    ExitLoop
                EndIf
            Next
            ; Deal with anything that does not match
            If $j > $aSortOrder[0] Then
                $aArray[$i][$iColumn] = StringFormat("%02i-", $j) & $aArray[$i][$iColumn]
            EndIf
        Next
    Else
        Switch $aSortData[$iRow][1]
            Case 0, 1
                ; Set required sort direction if no list
                If $aSortData[$iRow][1] Then
                    $iSortDirn = -1
                Else
                    $iSortDirn = 1
                EndIf
            Case Else
                Return SetError(1, 2, "")
        EndSwitch
    EndIf
    ; Sort the chunk
    Local $iSubMax = UBound($aArray, 2) - 1
    __ArrayQuickSort2D($aArray, $iSortDirn, $iChunkStart, $iChunkEnd, $iColumn, $iSubMax)
    ; Remove any prefixes
    If IsString($aSortData[$iRow][1]) Then
        For $i = $iChunkStart To $iChunkEnd
            $aArray[$i][$iColumn] = StringTrimLeft($aArray[$i][$iColumn], 3)
        Next
    EndIf
EndFunc   ;==>__AMCS_SortChunk
I am just off to cook dinner now - any questions will have to wait until later this evening. ;)

M23

1 person likes this

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

Reinhardt1julian,

Now I am fed and watered, did you get it to work as you wanted? :huh:

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

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

  • Similar Content

    • Anas
      By Anas
      Hi,

      Is it possible to set a different text direction/layout (not alignment) for a Listview column?
       
      Thanks.
    • Jibsbrown
      By Jibsbrown
      So trying to get an INI section in a listView with checkboxes. Was able to get the the section values to show until i add the checkboxes and now only the keys are show up. Between reading the Help file, Forum Topic and trying other code option. I have been unable to answer this problem. I'm assuming its something very basic I'm overlooking since this it's day 21 of learning Autoit.
      If someone could please advise I would appreciate the assistance.
       
      Here's the code: 
      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GUIListView.au3> #include <Array.au3> #include <File.au3> #include <ListViewConstants.au3> Global $sIniPath = "installLog.ini" ;ConsoleWrite($sIniPath) $iniSctionNames = IniReadSectionNames($sIniPath) ;_ArrayDisplay($iniSctionNames, "$iniSctionNames") $keys2 = IniReadSection($sIniPath, $iniSctionNames[2]) _ArrayDisplay($keys2 , "$keys2") ; Create GUI $hGUI = GUICreate("Test", 300, 250) ; Create ListView $cLV = GUICtrlCreateListView("", 10, 10, 200, 200,$LVS_List,$LVS_EX_CHECKBOXES) _GUICtrlListView_AddColumn($cLV, $keys2, 100) _GUICtrlListView_AddColumn($cLV, $keys2, 100) ;_GUICtrlListView_AddItem($cLV, $keys2, 0) _GUICtrlListView_AddArray($cLV, $keys2) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd And the INI file I'm using. 
      [OldSysInfo] 4=192.168.0.4|DESKTOP-RDIU2SN|R90M05Q8 5=192.168.0.5|SD0123456789101|R9WGP9P 6=192.168.0.6|SD0123456789102|R9WGP9PT 3=192.168.0.3|DESKTOP-3RS4LKL|R9WGP9P 23=192.168.0.23|SD0123456789102|MXL1234P5I [PrinterIp] 50=192.168.0.50 48=192.168.0.48 47=192.168.0.47 [NewSysInfo] newPC = SD0123456789adfs|192.168.0.185|2UA1234FTR Also if possible could you explain how to hide the Array count row as well.
    • buymeapc
      By buymeapc
      Hi all,
      I'm trying to create a listview with subitem icons and I achieved this by simply rearranging the order of the columns, so that the first column is in the middle, thus appearing as a subitem with an icon - this method prevents the "icon clipping" that happens when using subitem icons in a listview. My issue is that when I select a row that does not have an icon, the space where the icon would be is white. Is there a way to make this transparent, so it looks like the entire row is selected?
      Here's an example - click the second listview item/row to see a blank space where the icon would be.
      #include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> _Main() Func _Main() Local $hGui, $listview, $hImage Local $iLV_EXStyle_NoChecks = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER, $LVS_EX_HEADERDRAGDROP) $hGui = GUICreate("Listview Test With Icons", 400, 300) $listview = GUICtrlCreateListView("Col 1|Col 2|Col 3", 2, 2, 394, 268, BitOR($LVS_REPORT, $LVS_SHAREIMAGELISTS)) _GUICtrlListView_SetExtendedListViewStyle($listview, $iLV_EXStyle_NoChecks) GUISetState() ; Create the image list $hImage = _GUIImageList_Create(16, 16, 5, 3) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 165) _GUICtrlListView_SetImageList($listview, $hImage, 1) ; Set the order so the first column is moved to the middle, ; acting like a subitem with an icon _GUICtrlListView_SetColumnOrder($listview, "1|0|2") ; Add the items GUICtrlCreateListViewItem("Item1|Item2|Item3", $listview) GUICtrlCreateListViewItem("Item4|Item5|Item6", $listview) ; Set an icon for just the first item _GUICtrlListView_SetItemImage($listview, 0, 0) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main  
    • Luigi
      By Luigi
      Greetings forum,
      Hi develop this script, to use context menu with listview.
      It's work fine, run and click with left or right mouse button, you see on Console the id from item.
      If you click none, the id is -1, like this:
      $NM_RCLICK[-1] $NM_RCLICK[-1] $NM_RCLICK[2] $NM_RCLICK[1] $NM_RCLICK[0] $NM_RCLICK[1] That is correct.
      But if you uncoment the line:
      GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")
      You have to click with left button (over item or none) and after click with right button.
      LeftButton is to update $HOSTS_INDEX.
      RightButton is to open ContextMenu.
       
      Exist another way to update $HOSTS_INDEX?
      Example:
      Call WM_NOTIFY every time WM_CONTEXTMENU is called?
      I ask this, becouse i cant understanding why $HOSTS_INDEX is not updated when WM_CONTEXTMENU is uncomented.
      Someone can explain or help me?
       
      Best regards.
      ;~ #AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;~ #Tidy_Parameters=/sf #include-once #include-once #include <Array.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiMenu.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <SendMessage.au3> #include <Timers.au3> #include <AutoItConstants.au3> #include <EditConstants.au3> #include <File.au3> #include <FontConstants.au3> #include <GuiComboBoxEx.au3> #include <GuiImageList.au3> #include <GuiTreeView.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <TreeViewConstants.au3> #include <String.au3> OnAutoItExitRegister("OnExit") Opt("GUIOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("MustDeclareVars", 1) Global Enum $eCREATE = 1000, $eUPDATE, $eDELETE, $eICON_TABLE, $eDEFAULT, $eEXPORT_HTML Global Const $EMPTY = -1 Global $HOSTS_INDEX = -1 Global $HOST_Host Global $aGuiSize[2] = [800, 600] Global $sGuiTitle = "GuiTitle" Global $hGui Global $iList, $hList $hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1]) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") $iList = GUICtrlCreateListView("nome", 20, 50, 240, 490) $hList = GUICtrlGetHandle($iList) _GUICtrlListView_SetColumnWidth($hList, 0, 236) Populate() GUISetState(@SW_SHOW, $hGui) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;~ GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") While Sleep(25) WEnd Func OnExit() GUISetState($hGui, @SW_HIDE) GUIDelete($hGui) EndFunc ;==>OnExit Func Quit() Exit EndFunc ;==>Quit Func Populate() Local $arr[4] = [3, "nome 1", "nome 2", "nome 3"] _GUICtrlListView_BeginUpdate($hList) _GUICtrlListView_DeleteAllItems($hList) For $ii = 1 To $arr[0] _GUICtrlListView_AddItem($hList, $arr[$ii]) Next _GUICtrlListView_SetItemSelected($hList, 0, True, True) _GUICtrlListView_EndUpdate($hList) EndFunc ;==>Populate Func WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam ConsoleWrite("WM_CONTEXTMENU..( $hWnd=" & $hWnd & ", $iMsg=" & $iMsg & ", $wParam=" & $wParam & ", $lParam=" & $lParam & " )" & @LF) Local $exec = 0 Local $hMenu Switch $wParam Case $hList Local $TRY_ID = _GUICtrlListView_GetHotItem($hList) If Not ($TRY_ID = $HOSTS_INDEX) Then $HOSTS_INDEX = $TRY_ID Local $aOrigin = _GUICtrlListView_GetOrigin($hList) ConsoleWrite("WM_CONTEXTMENU $HOSTS_INDEX[" & $HOSTS_INDEX & "] $aOrigin[" & _GUICtrlListView_GetOriginX($iList) & "]" & @LF) $hMenu = _GUICtrlMenu_CreatePopup() If $HOSTS_INDEX = $EMPTY Then _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Add", $eCREATE) Else _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Rename", $eUPDATE) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Del", $eDELETE) EndIf _GUICtrlMenu_SetMenu($hGui, $hMenu) $exec = _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam, -1, -1, 1, 1, 2, 1) _GUICtrlMenu_DestroyMenu($hMenu) EndSwitch Return True EndFunc ;==>WM_CONTEXTMENU Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Local $TRY_ID Switch $hWndFrom Case $hList $TRY_ID = _GUICtrlListView_GetHotItem($hList) If Not ($TRY_ID = $HOSTS_INDEX) Then $HOSTS_INDEX = $TRY_ID Switch $iCode Case $NM_CLICK ConsoleWrite("$NM_CLICK[" & $TRY_ID & "]" & @LF) If $HOSTS_INDEX = $EMPTY Or $HOST_Host Then ;~ HOSTS_Clear() ;~ HOSTS_ListView_ItemCancel() ;~ GUICtrlSetState($HOSTS_ITEM_DEL, $GUI_DISABLE) ;~ GUICtrlSetState($HOSTS_ITEM_UPD, $GUI_DISABLE) Else Local $name = _GUICtrlListView_GetItemText($hList, $HOSTS_INDEX) ;~ HOSTS_FieldLoad($name) ;~ GUICtrlSetState($HOSTS_ITEM_DEL, $GUI_ENABLE) ;~ GUICtrlSetState($HOSTS_ITEM_UPD, $GUI_ENABLE) EndIf Return 0 ; allow the default processing Case $NM_RCLICK ConsoleWrite("$NM_RCLICK[" & $TRY_ID & "]" & @LF) Return 0 ; allow the default processing EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY  
    • amphoric
      By amphoric
      Hi,
      I am struggling converting my 1D array to a 2D array and then showing that in my List View. Below is my current code, where I would like to take the array from the input box, and have that displayed as a list within the list view this is a list of computer names, and then update the 2nd column of each line once I have ran a ping and a registry change on each computer name, with either 'Completed' and 'Failed'
      I have checked out the AutoIt Arrays page here: https://www.autoitscript.com/wiki/Arrays , but unfortunately I cannot get my head around it. Any help would be greatly appreciated.
      I hope this makes sense.
      Thanks
       
      #include <Date.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <MsgBoxConstants.au3> #include <GUIListBox.au3> #include <GuiListView.au3> #Region ### $Form1 = GUICreate("Title", 515, 533, -1, -1) GUISetBkColor(0xFFFFFF) $Pic2 = GUICtrlCreatePic("Images\pic.jpg", 16, 16, 212, 28) $Label1 = GUICtrlCreateLabel("Label", 240, 16, 271, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "") $Combo1 = GUICtrlCreateCombo("", 256, 406, 241, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE)) $Label2 = GUICtrlCreateLabel("Please select the location", 45, 401, 210, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "") $ChangeButton = GUICtrlCreateButton("Change", 286, 487, 75, 25) $RePromptButton = GUICtrlCreateButton("Re-prompt User", 366, 487, 139, 25) $Checkbox1 = GUICtrlCreateCheckbox("I have ensured that my selection is correct.", 10, 487, 273, 25) GUICtrlSetFont(-1, 10, 400, 0, "") $ManLocation = GUICtrlCreateLabel("Please enter the location:", 59, 448, 189, 20, $SS_RIGHT) GUICtrlSetFont(-1, 10, 800, 0, "") GUICtrlSetState(-1, $GUI_HIDE) $ManLocInput = GUICtrlCreateInput("", 256, 445, 241, 24) GUICtrlSetState(-1, $GUI_HIDE) $Label5 = GUICtrlCreateLabel("for this device:", 138, 418, 109, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "") $Label3 = GUICtrlCreateLabel("Asset Number:", 98, 72, 107, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "") $Input1 = GUICtrlCreateInput("", 215, 69, 241, 24) $AddMulti = GUICtrlCreateLabel("Add Multiple Assets", 356, 55, 98, 13, $SS_RIGHT) GUICtrlSetFont(-1, 8, 400, 6, "") GUICtrlSetColor(-1, 0x808080) GUICtrlSetCursor (-1, 0) $List1 = GUICtrlCreateListView("", 16, 104, 481, 278) $Add = GUICtrlCreateButton("Add", 461, 68, 35, 25) GUISetState(@SW_SHOW) #EndRegion ### ;### StartForm ### $FormaMultiple = GUICreate("Title", 277, 418, -1, -1) GUISetBkColor(0xFFFFFF) $Label1 = GUICtrlCreateLabel("Please add 1 asset number per line.", 8, 11, 253, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $OK = GUICtrlCreateButton("OK", 56, 375, 75, 25) $Edit1 = GUICtrlCreateEdit("", 20, 40, 233, 329) $Cancel = GUICtrlCreateButton("Cancel", 136, 375, 75, 25) GUISetState(@SW_HIDE) ;### EndForm ### ;### Add List View Columns START ### ;### Add List View Columns END ### ;### Read Locations START ### ;Read the LOCAL ini file SECTIONS Global $aSections = IniReadSectionNames("Locations.ini") ;If the above succeeded, convert the array to a string with each item separated by a | (pipe) and set the default selected item to $aSections[1] If(Not @Error) Then GUICtrlSetData($Combo1, _ArraytoString($aSections, "|", 1), $aSections[1]) ;### Read Locations END ### ;### Require Admin START ### ;#RequireAdmin ;### Require Admin END ### While 1 $nMsg = GUIGetMsg() ;### Data Validation START ### ;Set Checkbox = ENABLE/DISABLE if not GUICtrlRead($Combo1) = "" AND GUICtrlRead($Combo1) = "Not In List" then if not GUICtrlRead($ManLocInput) = "" Then If not ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_ENABLE) Else If ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_DISABLE) EndIf Else if GUICtrlRead($Combo1) = "" Then If ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_DISABLE) Else If not ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_ENABLE) EndIf EndIf ;Set Button = ENABLE/DISABLE If GUICtrlRead($Checkbox1) = 1 Then If Not ControlCommand($Form1, "", $ChangeButton, "IsEnabled") Then GUICtrlSetState($ChangeButton, $GUI_ENABLE) Else If ControlCommand($Form1, "", $ChangeButton, "IsEnabled") Then GUICtrlSetState($ChangeButton, $GUI_DISABLE) EndIf ;### Data Validation END ### Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $Add Case $AddMulti GUISetState(@SW_SHOW, $FormaMultiple) Case $Cancel GUISetState(@SW_HIDE, $FormaMultiple) Case $OK $sText = GUICtrlRead($Edit1) $aText = StringSplit($sText, @CRLF, 1) $bText = _ArrayToString($aText, ";", 1, -1) $cText = StringStripWS($bText, $STR_STRIPALL ) $dText = StringReplace($cText,";;",";") GUICtrlSetData($Input1, $dText) GUICtrlSetData($Edit1, "") GUISetState(@SW_HIDE, $FormaMultiple) For $i = 1 To $aText[0] Next Case $Combo1 ; If the combo is actioned Switch GUICtrlRead($Combo1) Case "Not In List" ; Show the manual input controls GUICtrlSetState($ManLocation, $GUI_SHOW) GUICtrlSetState($ManLocInput, $GUI_SHOW) if ControlCommand($Form1, "", $Checkbox1, "IsChecked") then ControlCommand($Form1, "", $Checkbox1, "Uncheck") GUICtrlSetData($ManLocInput, "") Case Else ; Hide them GUICtrlSetState($ManLocation, $GUI_HIDE) GUICtrlSetState($ManLocInput, $GUI_HIDE) if ControlCommand($Form1, "", $Checkbox1, "IsChecked") then ControlCommand($Form1, "", $Checkbox1, "Uncheck") GUICtrlSetData($ManLocInput, "") EndSwitch Case $ChangeButton ChangeReg() Case $RePromptButton RemoveReg() EndSwitch WEnd Func ChangeReg() $MultiAssets = StringSplit(GUICtrlRead($Input1), ";", 1) For $i = 1 To $MultiAssets[0] ; Ping with a timeout of 250ms. Local $iPing = Ping($MultiAssets[$i], 250) If $iPing Then ; If a value greater than 0 was returned then do the following: if not GUICtrlRead($ManLocInput) = "" Then RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", "# - " & GUICtrlRead($ManLocInput)) RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", "# - " & GUICtrlRead($ManLocInput)) RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC) RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC) MsgBox($MB_SYSTEMMODAL, "Completed", "Completed") Else If not GUICtrlRead($Input1) = "" Then RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", GUICtrlRead($Combo1)) RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", GUICtrlRead($Combo1)) RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC) RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC) MsgBox($MB_SYSTEMMODAL, "Completed", $MultiAssets[$i] & @CRLF & " Changed to: " & GUICtrlRead($Combo1)) Else MsgBox($MB_SYSTEMMODAL, "Error", "Please ensure all boxes are completed") EndIf EndIf Else MsgBox($MB_SYSTEMMODAL, "Error", "This asset may be OFFLINE, unable to complete") EndIf Next EndFunc ;==>PingReg Func RemoveReg() $MultiAssets = StringSplit(GUICtrlRead($Input1), ";", 1) For $i = 1 To $MultiAssets[0] ; Ping with a timeout of 250ms. Local $iPing = Ping($MultiAssets[$i], 250) If $iPing Then ; If a value greater than 0 was returned then do the following: if not GUICtrlRead($ManLocInput) = "" Then RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", "") MsgBox($MB_SYSTEMMODAL, "Completed", "Completed") Else If not GUICtrlRead($Input1) = "" Then RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", "") MsgBox($MB_SYSTEMMODAL, "Completed", $MultiAssets[$i] & @CRLF & "CLEARED") Else MsgBox($MB_SYSTEMMODAL, "Error", "Please ensure all boxes are completed") EndIf EndIf Else MsgBox($MB_SYSTEMMODAL, "Error", "This asset may be OFFLINE, unable to complete") EndIf Next EndFunc ;==>PingReg1