Jump to content
Sign in to follow this  
Steve0

ListView Sort maintaining color information

Recommended Posts

Steve0

Hi there,

I hope someone out there can help me. I'm populating a ListView with a number of items and have color-coded the rows. Top 3 in one color, the next 6 in another color, any remaining in a third color. When clicking the header, the items in the ListView sort, but the row colors remain the same. Does anyone know of a function that will sort the contents of the ListView and maintain color information?

So far, I've tried two methods to create the ListView:

Attempt 1, the most basic.

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

$Form = GUICreate("Form", 400, 500, 500, 200)

$Listview = GUICtrlCreateListView("Col 1|Col 2|Col 3", 20, 20, 300, 400)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)

For $i = 1 to 18
    GUICtrlCreateListViewItem("Item 1|Item " & $i & "|Item " & (18 - $i), $Listview)
    If $i >= 1 And $i < 4 Then GUICtrlSetBkColor(-1, 0x00ff00)
    If $i >= 4 And $i < 10 Then GUICtrlSetBkColor(-1, 0x0000ff)
    If $i >= 10 Then GUICtrlSetBkColor(-1, 0xff0000)
 Next
 GUISetState(@SW_SHOW)

 Global $toggle = 1

While 1
    $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Listview
                _GUICtrlListView_SimpleSort($Listview, $toggle, GUICtrlGetState($Listview))

                If _GUICtrlListView_GetSelectedCount($Listview) Then 
                    $index = _GUICtrlListView_GetSelectedIndices($Listview, True) 
                    For $i = 1 To $index[0]
                        _GUICtrlListView_SetItemSelected($listview, $index[$i], False,False)
                    Next
                Endif

            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
WEnd

Rows are colored correctly, but when sorting the color does not adjust accordingly.

Attempt 2 (partial), using a more advanced ListView:

$ListView = _GUICtrlListView_Create($Form, "", 20, 20, 300, 400)
_GUICtrlListView_AddColumn($ListView, "Col 1", 150)
_GUICtrlListView_AddColumn($ListView, "Col 2", 50)
_GUICtrlListView_AddColumn($ListView, "Col 3", 50)

For $i = 1 to 18
    _GUICtrlListView_AddItem($Listview, "Item 1", ($i-1))
    _GUICtrlListView_AddSubItem($Listview, ($i-1), "Item " & $i, 1)
    _GUICtrlListView_AddSubItem($Listview, ($i-1), "Item " & (18 - $i), 2)
    If $i >= 1 And $i < 4 Then _GUICtrlListView_SetTextBkColor($ListView, 0x00ff00)
Next

The SimpleSort function does not work with this method, but I didn't get as far as I was unable to find a way to individually color the rows - the _GUICtrlListView_SetTextBkColor function colors ALL rows the same.

Any assistance would be greatly appreciated...

 

EDIT:  Nevermind, have found a solution courtesy of BugFix's post >here. The SimpleSort in LV_Format_Include includes IParam, maintaining the row bkcolor.

 

Steve

Edited by Steve0

Share this post


Link to post
Share on other sites
guinness

It should be fixed in the latest beta.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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  

×