Save ListIcon Sort Order

Just starting out? Need help? Post your questions and find answers here.
User avatar
OldSkoolGamer
Enthusiast
Enthusiast
Posts: 150
Joined: Mon Dec 15, 2008 11:15 pm
Location: Nashville, TN
Contact:

Save ListIcon Sort Order

Post by OldSkoolGamer »

Is there any way to save a listicon's sort order so that on the next run of your application it sorts the same way as it was when the application was closed? Searched the forum and looked on MSDN without any success, but maybe I'm not using the correct terminology?
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Save ListIcon Sort Order

Post by IdeasVacuum »

Perhaps you can record the sort order in a .txt or .ini file?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
spikey
Enthusiast
Enthusiast
Posts: 586
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Save ListIcon Sort Order

Post by spikey »

Two procedures, one converts the current column order to a string representation like 'GCDEFAB' which could be stored in a preference file or in the registry as a string, and the other does the reverse. As ASCII capital letters are used a maximum of 26 columns are supported.

Code: Select all

Procedure.S fLSIColumnOrderGet(aListView.I)
  ; Convert the column order to a string representation.
  ; Maximum 26 columns.
    
  Protected.I lintCols, lintNumCols, hHeader
  Protected.S lstrOrder
  Protected Dim larrColOrder.I(1)
  
  If GadgetType(aListView) <> #PB_GadgetType_ListIcon
    ProcedureReturn #Empty$
  EndIf
  
  hHeader  = SendMessage_(GadgetID(aListView), #LVM_GETHEADER, 0, 0)
  lintNumCols = SendMessage_(hHeader,  #HDM_GETITEMCOUNT, 0, 0) - 1
  
  If lintNumCols > 25
    ProcedureReturn #Empty$
  EndIf
  
  ReDim larrColOrder(lintNumCols)
  
  SendMessage_(GadgetID(aListView), #LVM_GETCOLUMNORDERARRAY, lintNumCols + 1, larrColOrder())
  
  For lintCols = 0 To lintNumCols
    lstrOrder = lstrOrder + Chr(larrColOrder(lintCols) + 65)
  Next lintCols
  
  ProcedureReturn lstrOrder
  
EndProcedure

Procedure fLSIColumnOrderSet(aListView.I, aOrder.S)
  ; Set the column order from a string representation.
  ; Maximum 26 columns.
  
  Protected.I lintCols, lintNumCols
  Protected.S lstrOrder
  Protected Dim larrColOrder.I(1)
  
  If GadgetType(aListView) <> #PB_GadgetType_ListIcon Or aOrder = #Empty$
    ProcedureReturn
  EndIf
  
  lintNumCols = Len(aOrder) - 1
  
  If lintNumCols > 25
    ProcedureReturn 
  EndIf
  
  ReDim larrColOrder(lintNumCols)
  lstrOrder = UCase(aOrder)
  
  For lintCols = 0 To lintNumCols
    larrColOrder(lintCols) = Asc(Mid(aOrder, lintCols + 1, 1)) - 65
  Next lintCols
  
  SendMessage_(GadgetID(aListView), #LVM_SETCOLUMNORDERARRAY, lintNumCols + 1, larrColOrder())  
  
EndProcedure
User avatar
OldSkoolGamer
Enthusiast
Enthusiast
Posts: 150
Joined: Mon Dec 15, 2008 11:15 pm
Location: Nashville, TN
Contact:

Re: Save ListIcon Sort Order

Post by OldSkoolGamer »

spikey wrote:Two procedures, one converts the current column order to a string representation like 'GCDEFAB' which could be stored in a preference file or in the registry as a string, and the other does the reverse. As ASCII capital letters are used a maximum of 26 columns are supported.
Thanks for the code Spikey, will test it out later. 8)
Post Reply