Just Another ListIcon Question...

Just starting out? Need help? Post your questions and find answers here.
User avatar
Shardik
Addict
Addict
Posts: 2065
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

Another solution which saves the current column order to disk and loads it after the program is started a second time to rebuild the saved column order:

Code: Select all

#LVM_GETCOLUMNORDERARRAY = #LVM_FIRST + 59
#LVM_SETCOLUMNORDERARRAY = #LVM_FIRST + 58

#Filename = "C:\ColumnOrder.Dat"
#NumColumns = 3

#WindowID = 0
#WindowHeight = 200
#WindowWidth = 202

Enumeration
  #ListIconID
  #SaveButtonID
  #CancelButtonID
EndEnumeration

ArrayBufferPtr.L
i.W
WindowEvent.L

ArrayBufferPtr = AllocateMemory(#NumColumns * 4)

If OpenWindow(#WindowID, 0, 0, #WindowWidth, #WindowHeight,  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "ListIcon HeaderDrag-Demo")
  If CreateGadgetList(WindowID())
    ListIconGadget(#ListIconID, 9, 12, 184, 149, "Column 1", 60, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection | #PB_ListIcon_HeaderDragDrop)
    ButtonGadget(#SaveButtonID, 10, #WindowHeight - 30, 110, 20, "Save Column Order")
    ButtonGadget(#CancelButtonID, #WindowWidth - 70, #WindowHeight - 30, 60, 20, "Cancel")
    
    For i = 2 To #NumColumns
      AddGadgetColumn(#ListIconID, i - 1, "Column " + Str(i), 60)
    Next i  

    For i = 1 To 9
      AddGadgetItem(#ListIconID, -1, "R" + Str(i) + " + C1" + #LF$ + "R" + Str(i) + " + C2" + #LF$ + "R" + Str(i) + " + C3")
    Next i  

    If ReadFile(1, #Filename)
      For i = 0 To #NumColumns - 1
        PokeL(ArrayBufferPtr + i * 4, ReadLong())
      Next i

      CloseFile(1)

      SendMessage_(GadgetID(#ListIconID), #LVM_SETCOLUMNORDERARRAY, #NumColumns, ArrayBufferPtr)
    EndIf

    Repeat
      WindowEvent = WaitWindowEvent()

      If WindowEvent = #PB_Event_Gadget
        Select EventGadgetID()
          Case #SaveButtonID
            If CreateFile(1, #Filename)
              If SendMessage_(GadgetID(#ListIconID), #LVM_GETCOLUMNORDERARRAY, 3, ArrayBufferPtr) <> #False
                For i = 0 To #NumColumns - 1
                  WriteLong(PeekL(ArrayBufferPtr + i * 4))
                Next i

                CloseFile(1)
              EndIf
            EndIf

            Break
          Case #CancelButtonID
            Break
        EndSelect
      EndIf
    Until WindowEvent = #PB_Event_CloseWindow
  EndIf
EndIf
For the information to read the actual column order with LVM_GETCOLUMNORDERARRAY, take a look in the MSDN:
http://msdn.microsoft.com/library/defau ... rarray.asp
User avatar
kenmo
Addict
Addict
Posts: 2049
Joined: Tue Dec 23, 2003 3:54 am

Post by kenmo »

Wow, thanks to all three of you!
Post Reply