Page 1 of 1

How do I reorder items in listview using drag and drop?

Posted: Sat Nov 22, 2003 11:13 pm
by storck
Hi all!

Can anyone tell me how to reorder items in a listview using drag and drop? I have been searching the forums, but I can't seem to find any example.

Regards,

Storck

Posted: Sat Nov 22, 2003 11:36 pm
by GPI
I do a drag&drop-Sort in the Todo-Plugin (but for IconList).

download the japbe-source and look in the source\Plugin\Todo

GPI

Posted: Sun Nov 23, 2003 9:02 am
by storck
Thank you GPI, I'll have a look.

By the way, many thanks for jaPEe. It's a great tool!

Regards,

Storck

Posted: Sun Nov 23, 2003 3:37 pm
by storck
:? I think I will have to gain some more experience. I do get the general idea since I've been programming c++ builder, but I guess I'll have to learn more about purebasic and api to pull this one off.

Thanks anyway :oops:

/Storck

Posted: Sun Nov 23, 2003 7:24 pm
by Hi-Toro
Not sure how to sort yet (needs an application-defined function, which I haven't yet experimented with), but this might give some idea of how to deal with the sending of messages to listviews (which is what PB's 'ListView/ListIconGadgets' are)...

Code: Select all


; Custom listview example...

; The messages and constants used are found at the URL below. If a constant's value isn't defined in PB, just hit
; Google with (eg.) "const LVM_SETICONSPACING" (minus the quotes)... nearly always works :)

; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listview/listview.asp




; This is just used to resize the listview gadget with the window, in realtime...

Procedure WindowHook (WindowID, Message, wParam, lParam) 
    result = #PB_ProcessPureBasicEvents
    Select Message
        Case #WM_SIZE
            ResizeGadget (0, 0, 0, WindowWidth (), WindowHeight ())
    EndSelect
    ProcedureReturn result
EndProcedure

; Missing listview message definition...

#LVM_SETICONSPACING = #LVM_FIRST + 53

If OpenWindow (0, 0, 0, 400, 300, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered, "Test gadget")

    SetWindowCallback (@WindowHook ())
    
    CreateGadgetList (WindowID ())

    ; Create list icon gadget and store its Windows handle in 'lv'...
        
    lv = ListIconGadget (0, 0, 0, WindowWidth (), WindowHeight (), "Test", WindowWidth (), #PB_ListIcon_MultiSelect | #LVS_AUTOARRANGE | #LVS_NOSCROLL)
    ChangeListIconGadgetDisplay (0, 0)

    ; Set spacing of icons to 64 x 64 (has to be combined into a .l variable)...
    
    PokeW (@size, 64)
    PokeW (@size + 2, 64)
    SendMessage_ (lv, #LVM_SETICONSPACING, 0, size)
    
    ; Get an icon (may need to change .exe used). Haven't yet figured out how to make the background transparent...
    
    icon = ExtractIcon_ (GetModuleHandle_ (#NULL), "C:\Program Files\Accessories\mspaint.exe", 0)

    ; Stick the icon into a PB image...
        
    image = CreateImage (0, 32, 32)
    dc = StartDrawing (ImageOutput ())
    DrawIcon_ (dc, 0, 0, icon)
    StopDrawing ()

    ; Add some test items...
        
    For a = 1 To 10
        AddGadgetItem (0, -1, "Test", ImageID ())
    Next
        
    Repeat
        ; Wait until window is closed...
    Until WaitWindowEvent () = #PB_Event_CloseWindow
    
EndIf