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

    • mLipok
      By mLipok
      I was not lucky to find the right function so I created it by my self:
      _GUICtrlListView_GetColumnID_ByName()
      Example:
       
      #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("ListView Get Column ID", 400, 300) Local $idListview = GUICtrlCreateListView("Alfa|Beta|Gama", 2, 2, 394, 268) GUISetState(@SW_SHOW) _GUICtrlListView_SetColumnOrder($idListview, "2|0|1") MsgBox($MB_SYSTEMMODAL, "Information", "Column ID: " & _GUICtrlListView_GetColumnID_ByName($idListview, 'Gama')) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func _GUICtrlListView_GetColumnID_ByName($hListView, $sColumnToFind) Local $iColumn_Count = _GUICtrlListView_GetColumnCount($hListView) Local $aColumns For $iColumn_idx = 0 To $iColumn_Count - 1 $aColumns = _GUICtrlListView_GetColumn($hListView, $iColumn_idx) If $aColumns[5] = $sColumnToFind Then Return $iColumn_idx EndIf Next Return SetError(1, 0, -1) EndFunc ;==>_GUICtrlListView_GetColumnID_ByName  
    • UEZ
      By UEZ
      Here a small tool I wrote to update my Sysinternal tools collection without the need to download always the whole package or visiting the site to check for updates. I know that there are several tools available (also some tools written in AutoIt) but here another one for the collection. It was good exercise for me to code it.
       
       
        
       
       
      Some files from cannot be downloaded although they are visible on the web site!
       
      Here the download link of the source code only: AutoIt Sysinternal Tools Synchronizer v0.99.1 build 2017-10-23 beta.7z  (1353 downloads previously)
      -=> Requires AutoIt version 3.3.13.20 or higher / tested on Win8.1 real machine and some VMs: Win7 / Vista / Win10
       
      Compiled exe only: @MediaFire
       
      Just select the Sysinternal Tools folder or create one and press the synchronize button to download the selected items. Click on AutoIt label (near to left upper corner) to open menu.
       
      Special thanks to LarsJ, Melba23 and mesale0077 for their help. 
       
      I've still some ideas to implement which are more gimmick related, so it is not finished yet...
      If you want to add your language please check out #Region Language. Thanks. 
       
      Please report any bug or if you have any suggestions.
       
      The language of the tool tip from each of the executable in the left list view were automatically created using Google translator and weren't checked for correctness.
       
      Br,
      UEZ
    • 0Ethan0
      By 0Ethan0
      Ahoy Autoit Community!
      After many trials and errors I am unable to solve a problem I am facing and would appreciate any kind of input or better yet a solution 
      The Premise: An embeded slideshow viewer that runs after double-clicking an item in a ListView (each item will generate a different slideshow images).
      The Setup: GUI with a ListView Control and a simple exit button.
      The Issue: Once double clicked the slide plays however the GUI "locks"/non responsive until the slide is over. Same thing if I click on the "Test" button.
      The Culprit: I believe since it's in the images loop it can't accept any other commands until that loop is over.
      The Wish: I want to be able to use the GUI functions (selecting other items, clicking on button etc.) while the slideshow plays.
      The Code (stripped and simplified as much as I could):
      #include <GuiListView.au3> #include <File.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) HotKeySet("{Esc}", "_Exit") Global $c=0 Global $ssGDI[3], $ssGraphic[2], $ssImage Global Const $bg_color = "000000" Global Const $ssW = 480, $ssH = 320 Global $aFiles = _FileListToArrayRec("d:\testStage\", "*.jpg;*.png;*.bmp;*.gif;*.JPG;*.PNG;*.BMP;*.GIF", $FLTAR_FILES, $FLTAR_NORECUR ,$FLTAR_SORT ,$FLTAR_FULLPATH ) $guiW = 1200 $guiH = 726 $mainWindow = GUICreate("Slideshow Viewer", $guiW, $guiH, -1, -1, $WS_POPUP) $Button1 = GUICtrlCreateButton("Exit", 0, 0, 50, 50) GUICtrlSetOnEvent($Button1, "_Exit") $Button1 = GUICtrlCreateButton("Test", 60, 0, 50, 50) GUICtrlSetOnEvent($Button1, "Test") Global $ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280) _GUICtrlListView_SetColumnWidth ($ListView, 0, 100) _GUICtrlListView_SetColumnWidth ($ListView, 1, 100) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("Name 1|Category 1", $ListView) GUICtrlCreateListViewItem("Name 2|Category 2", $ListView) screenshotWidgetInit($ssW,$ssH, 690, 100) GUISetState(@SW_SHOW, $mainWindow) GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Exit() EndSwitch WEnd Func Test() For $k = 1 To UBound($aFiles) - 1 screenshotWidgetTransition($aFiles[$k]) Next EndFunc Func ListView_Click() ConsoleWrite("Left Click") EndFunc Func ListView_DoubleClick() ConsoleWrite("Double Left Click") Test() EndFunc Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $ListView Select Case $event = $NM_CLICK ListView_Click () Case $event = $NM_DBLCLK ListView_DoubleClick () EndSelect EndSelect Return $GUI_RUNDEFMSG EndFunc Func screenshotWidgetTransition($image, $delay = 0, $speed = 1, $sleep = 2000) Local $a, $d = $c, $iX, $iY $ssImage = _GDIPlus_ImageLoadFromFile($image) $iX = _GDIPlus_ImageGetWidth($ssImage) $iY = _GDIPlus_ImageGetHeight($ssImage) $FDesktop=$ssH/$ssW $Fact =1 If $iX > $ssW And $FDesktop > ($iY/$iX) Then $Fact=$ssW/$iX ElseIf $iY > $ssH Then $Fact=$ssH/$iY EndIf $H1 = Round(($Fact * $iY),0) $W1 = Round(($Fact * $iX),0) _GDIPlus_GraphicsDrawImageRect($ssGraphic[$d], $ssImage,($ssW - $W1)/2, ($ssH - $H1) / 2,$W1,$H1) WinSetTrans($ssGDI[$d], "", 0) WinSetOnTop($ssGDI[$d], "", 1) For $a = 0 To 254 Step $speed WinSetTrans($ssGDI[$d], "", $a) Sleep($delay) Next WinSetTrans($ssGDI[$d], "", 254) WinSetOnTop($ssGDI[Not ($d)], "", 0) WinSetTrans($ssGDI[Not ($d)], "", 0) _GDIPlus_GraphicsClear($ssGraphic[Not ($d)]) $c = 1 - $d _GDIPlus_ImageDispose ($ssImage) ; very important to realease the pics Sleep($sleep) EndFunc ;==>screenshotWidgetTransition Func screenshotWidgetInit($ssW,$ssH,$ssX,$ssY) $ssGDI[2] = GUICreate("", $ssW, $ssH, $ssX, $ssY, $WS_POPUP, $WS_EX_MDICHILD, $mainWindow) $ssGDI[0] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2]) $ssGDI[1] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2]) ; GUISetBkColor("0x" & $bg_color, $ssGDI[2]) GUISetState(@SW_SHOW, $ssGDI[2]) GUISetState(@SW_SHOW, $ssGDI[0]) GUISetState(@SW_SHOW, $ssGDI[1]) WinSetTrans($ssGDI[0], "", 0) WinSetTrans($ssGDI[1], "", 0) _GDIPlus_Startup() $ssGraphic[0] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[0]) $ssGraphic[1] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[1]) _GDIPlus_GraphicsClear($ssGraphic[0], "0xFF" & $bg_color) _GDIPlus_GraphicsClear($ssGraphic[1], "0xFF" & $bg_color) EndFunc ;==>screenshotWidgetInit Func _Exit() _GDIPlus_ImageDispose($ssImage) _GDIPlus_GraphicsDispose($ssGraphic[0]) _GDIPlus_GraphicsDispose($ssGraphic[1]) GUIDelete($ssGDI[0]) GUIDelete($ssGDI[1]) GUIDelete($ssGDI[2]) _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit I hope someone can shed light on this; perhaps a different approach is needed?
      Thank you in advance!
      P.S.
      The script is patched from different scripts of different users in the forum - thank you again users!
    • Daka
      By Daka
      I know there are listbox and listview, but now I have?
      here is the video of infowindow 
      I tried to read mouse selection like for listbox:
      $listWindow = "[CLASS:TFormResearchGR]" $topicsList = "[CLASS:TMWrapper; INSTANCE:255]" WinWait($listWindow, "", 60) $hdlWindow = WinGetHandle($listWindow) $hdlList = ControlGetHandle($hdlWindow, "", $topicsList) _GUICtrlListBox_ClickItem($hdlList, 0, "left") $countOfList = _GUICtrlListBox_GetCount($hdlList) ConsoleWrite("Count of list: " & $countOfList & @LF) count of list is not working.
      I realiezed that there are difference between listbox and listview, but this is something different.
      and till now I never saw that you can go inside with infotool and also get instances.
       
      so Im confused how to get the list number and the names of selection?
    • AndyS19
      By AndyS19
      I have a listview with 3 columns and I want to set the 3rd column's color based on the item's 'Param' value, but even though I set up for the 3rd column, the entire row always gets the color.
      My test code is below, but here is the pertinent code:
      Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg
      Here is the full test code:
      #include-once ;#cs #NoTrayIcon #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_UseX64=N Opt("GUICloseOnESC", 1) ; ESC closes GUI? (0 = no, 1 = yes) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Opt('MustDeclareVars', 1) OnAutoItExitRegister("_test_exit") Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase #include <GuiListBox.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> Global $__MCP_obj, $__MCP_GUI_hWnd, $idListView, $hListView Global $hMainWin test() Exit Func test() $hMainWin = GUICreate("Test window", 120, 100, @DesktopWidth / 2, -1) GUICtrlCreateButton("Hwnd", 10, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_1stTEST_btn") GUICtrlCreateButton("ID", 50, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_2ndTEST_btn") GUISetOnEvent($GUI_EVENT_CLOSE, "_test_exit") GUISetState(@SW_SHOW) While (1) Sleep(17) WEnd EndFunc ;==>test Func _myColorPicker($obj) logmsg("+++: $obj = 0x" & Hex($obj) & @CRLF) Local $flags = 0 Local $ww, $wh, $x, $y, $w, $h $__MCP_obj = $obj $ww = 350 $wh = 500 $x = 200 $y = 150 $__MCP_GUI_hWnd = GUICreate("myColorPicker", $ww, $wh, $x, $y, $flags) $x = 10 $y = 10 $w = 150 $h = 20 GUICtrlCreateButton("Set caller's color", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_SetColor_btn") $y += $h + 5 $w = $ww - 25 $h = $wh - 100 $idListView = GUICtrlCreateListView("", $x, $y, $w, $h, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $hListView = GUICtrlGetHandle($idListView) $x = $ww / 2 - 50 $y = $wh - 60 $w = 100 $h = 25 GUICtrlCreateButton("Quit Popup", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_QUIT_btn") GUICtrlSetFont($idListView, 8.5, -1, -1, "courier new") _GUICtrlListView_AddColumn($idListView, "Name", 100) _GUICtrlListView_AddColumn($idListView, "Value", 100) _GUICtrlListView_AddColumn($idListView, "Sample", 100) _GUICtrlListView_SetColumnWidth($idListView, 0, 100) _GUICtrlListView_SetColumnWidth($idListView, 1, 80) logmsg("+++: $idListView = " & $idListView) logmsg("+++: $hListView = 0x" & Hex($hListView)) __MCP_populateListView($hListView) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW, $__MCP_GUI_hWnd) EndFunc ;==>_myColorPicker Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg Func __MCP_exit() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_exit Func __MCP_handle_SetColor_btn() If (IsHWnd($__MCP_obj)) Then GUISetBkColor($COLOR_BLUE, $__MCP_obj) Else GUICtrlSetBkColor($__MCP_obj, $COLOR_BLUE) EndIf EndFunc ;==>__MCP_handle_SetColor_btn Func __MCP_populateListView($hWnd) Local $text, $parts, $iIndex Local Static $aItems[] = [ _ "BLACK | " & $CLR_BLACK & "|" & "", _ "BLUE | " & $CLR_BLUE & "|" & "", _ "RED | " & $CLR_RED & "|" & "", _ "WHITE | " & $CLR_WHITE & "|" & "", _ "YELLOW | " & $CLR_YELLOW & "|" & "" _ ] _GUICtrlListView_BeginUpdate($hWnd) _GUICtrlListView_DeleteAllItems($hWnd) For $ndx = 0 To UBound($aItems) - 1 $text = $aItems[$ndx] $parts = StringSplit($text, "|", 2) $parts[0] = StringStripWS($parts[0], 3) $parts[2] = StringStripWS($parts[2], 3) $iIndex = _GUICtrlListView_AddItem($hWnd, $parts[0], -1, $parts[1]) _GUICtrlListView_AddSubItem($hWnd, $iIndex, Hex($parts[1]), 1) _GUICtrlListView_AddSubItem($hWnd, $iIndex, $parts[0], 2) Next _GUICtrlListView_EndUpdate($hWnd) EndFunc ;==>__MCP_populateListView Func __MCP_handle_QUIT_btn() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_handle_QUIT_btn Func handle_1stTEST_btn() _myColorPicker($hMainWin) EndFunc ;==>handle_1stTEST_btn Func handle_2ndTEST_btn() _myColorPicker(@GUI_CtrlId) EndFunc ;==>handle_2ndTEST_btn Func _test_exit() Exit EndFunc ;==>_test_exit