HeaderDragDrop, get new position?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

HeaderDragDrop, get new position?

Post by Joakim Christiansen »

With #PB_ListIcon_HeaderDragDrop how can I know which position the column has if the user has moved it?
I like logic, hence I dislike humans but love computers.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Code: Select all

#HDN_ENDDRAG = #HDN_FIRST - 11
#HDM_GETORDERARRAY = #HDM_FIRST + 17

;... Need this updated HDITEM structure for accessing iOrder member
;... IE 5 or greater is required so I think we're safe using it

Structure _HDITEM
  mask.l
  cxy.l
  pszText.l
  hbm.l
  cchTextMax.l
  fmt.l
  lParam.l
  iImage.l
  iOrder.l
  type.l
  pvFilter.l
EndStructure

Procedure WinProc(hwnd, msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_NOTIFY
      *pnmhdr.NMHDR = lParam
      Select *pnmhdr\code
        Case #HDN_ENDDRAG
          *pnmhead.NMHEADER = lParam
          *hdi._HDITEM = *pnmhead\pitem
          SetWindowTitle(0, "Column " + Str(*pnmhead\iItem) + " was moved to Column " + Str(*hdi\iOrder))
      EndSelect
  EndSelect
  ProcedureReturn result
EndProcedure
If OpenWindow(0, 100, 100, 310, 200, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowCallback(@WinProc())
  If CreateGadgetList(WindowID(0))
    ListIconGadget(0, 5, 5, 300, 190, "Col 0", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_HeaderDragDrop)
    AddGadgetColumn(0, 1, "Col 1", 100)
    AddGadgetColumn(0, 2, "Col 2", 100)
    For i = 0 To 9
      AddGadgetItem(0, -1, "Item" + Str(i) + " Col 0" + Chr(10) + "Item" + Str(i) + " Col 1" + Chr(10) + "Item" + Str(i) + " Col 2" + Chr(10))
    Next
    
    Repeat
      event = WaitWindowEvent()
    Until event = #PB_Event_CloseWindow
  EndIf
EndIf
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

How nice, thank you very much! :D
I like logic, hence I dislike humans but love computers.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

You're welcome. I'm just glad you didn't ask for a cross-platform solution. 8)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: HeaderDragDrop, get new position?

Post by Kwai chang caine »

After one thousand of year..i have the same problem :oops:

That work at the moment of the drag, but the order is not changed with GetGadgetItemText() :cry:
How can i obtain the good order of the column when i close the window ?

Code: Select all

#HDN_ENDDRAG = #HDN_FIRST - 11
#HDM_GETORDERARRAY = #HDM_FIRST + 17

;... Need this updated HDITEM structure for accessing iOrder member
;... IE 5 or greater is required so I think we're safe using it

Structure _HDITEM
  mask.l
  cxy.l
  pszText.l
  hbm.l
  cchTextMax.l
  fmt.l
  lParam.l
  iImage.l
  iOrder.l
  type.l
  pvFilter.l
EndStructure

Procedure WinProc(hwnd, msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_NOTIFY
      *pnmhdr.NMHDR = lParam
      Select *pnmhdr\code
        Case #HDN_ENDDRAG
          *pnmhead.NMHEADER = lParam
          *hdi._HDITEM = *pnmhead\pitem
          SetWindowTitle(0, "Column " + Str(*pnmhead\iItem) + " was moved to Column " + Str(*hdi\iOrder))
                   
      EndSelect
  EndSelect
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 100, 100, 310, 200, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowCallback(@WinProc())

    ListIconGadget(0, 5, 5, 300, 190, "Col 0", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_HeaderDragDrop)
    AddGadgetColumn(0, 1, "Col 1", 100)
    AddGadgetColumn(0, 2, "Col 2", 100)
    
    For i = 0 To 9
      AddGadgetItem(0, -1, "Item" + Str(i) + " Col 0" + Chr(10) + "Item" + Str(i) + " Col 1" + Chr(10) + "Item" + Str(i) + " Col 2" + Chr(10))
    Next
    
    Debug ""
    
    For i = 0 To 2
     Debug GetGadgetItemText(0, -1, i)
    Next 
    
    Repeat
      event = WaitWindowEvent()
    Until event = #PB_Event_CloseWindow
    
   Debug ""
          
   For i = 0 To 2
    Debug GetGadgetItemText(0, -1, i)
   Next 
  
EndIf
Have a good day
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: HeaderDragDrop, get new position?

Post by Kwai chang caine »

I have found the soulution thanks to SHARDICK code 8)

Code: Select all

#HDN_ENDDRAG = #HDN_FIRST - 11
#HDM_GETORDERARRAY = #HDM_FIRST + 17

;... Need this updated HDITEM structure for accessing iOrder member
;... IE 5 or greater is required so I think we're safe using it

Structure _HDITEM
  mask.l
  cxy.l
  pszText.l
  hbm.l
  cchTextMax.l
  fmt.l
  lParam.l
  iImage.l
  iOrder.l
  type.l
  pvFilter.l
EndStructure

ArrayBufferPtr = AllocateMemory(3 * 4) 

Procedure WinProc(hwnd, msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_NOTIFY
      *pnmhdr.NMHDR = lParam
      Select *pnmhdr\code
        Case #HDN_ENDDRAG
          *pnmhead.NMHEADER = lParam
          *hdi._HDITEM = *pnmhead\pitem
          SetWindowTitle(0, "Column " + Str(*pnmhead\iItem) + " was moved to Column " + Str(*hdi\iOrder))
                   
      EndSelect
  EndSelect
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 100, 100, 310, 200, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowCallback(@WinProc())

    ListIconGadget(0, 5, 5, 300, 190, "Col 0", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_HeaderDragDrop)
    AddGadgetColumn(0, 1, "Col 1", 100)
    AddGadgetColumn(0, 2, "Col 2", 100)
    
    For i = 0 To 9
      AddGadgetItem(0, -1, "Item" + Str(i) + " Col 0" + Chr(10) + "Item" + Str(i) + " Col 1" + Chr(10) + "Item" + Str(i) + " Col 2" + Chr(10))
    Next
    
    Debug ""
    
    For i = 0 To 2
     Debug GetGadgetItemText(0, -1, i)
    Next 
    
    Repeat
      event = WaitWindowEvent()
    Until event = #PB_Event_CloseWindow
      
    If SendMessage_(GadgetID(0), #LVM_GETCOLUMNORDERARRAY, 3, ArrayBufferPtr) <> #False 
    
     Debug ""
    
     For i = 0 To 2
      Debug GetGadgetItemText(0, -1, PeekL(ArrayBufferPtr + i * 4))
     Next 
           
    EndIf    
    
EndIf
ImageThe happiness is a road...
Not a destination
Post Reply