Page 1 of 1

ListIcon drag to select multiple rows

Posted: Wed Sep 25, 2013 6:04 pm
by IdeasVacuum
ListIconGadget() Drag mouse to select multiple rows, as you can with a ListView?

Re: ListIcon drag to select multiple rows

Posted: Sat Sep 28, 2013 8:32 pm
by netmaestro
3 days old, didja think we forgotcha? :mrgreen:

Code: Select all

Procedure ListHandler(hwnd, msg, wparam, lparam)
  oldproc = GetProp_(hwnd, "oldproc")
  
  Select msg
    Case #WM_NCDESTROY
      RemoveProp_(hwnd, "oldproc")
           
    Case #WM_MOUSEMOVE
      If GetAsyncKeyState_(#VK_LBUTTON) & $8000
        With lvh.LVHITTESTINFO
          \pt\x = lparam&$FFFF
          \pt\y = lparam>>16
        EndWith
        SendMessage_(GadgetID(0), #LVM_HITTEST, 0, @lvh)
        SetGadgetItemState(GetDlgCtrlID_(hwnd), lvh\iItem, 1)
      EndIf
      
  EndSelect
  
  ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
  
EndProcedure


If OpenWindow(0, 0, 0, 270, 240, "ListIconGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 10, 10, 250, 230,"col 0", 100,#PB_ListIcon_FullRowSelect|#PB_ListIcon_MultiSelect)
  SetProp_(GadgetID(0), "oldproc", SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @ListHandler()))
  AddGadgetColumn(0, 1,"col 1",165)
  For a = 1 To 12
    AddGadgetItem (0, -1, "Item " + Str(a)+Chr(10)+"More Item "+Str(a)) ; define listview content
  Next
  SetActiveGadget(0)

  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: ListIcon drag to select multiple rows

Posted: Sun Sep 29, 2013 6:47 am
by IdeasVacuum
Woo, thanks netmaestro! 8)
I forgot myself a long time ago, the PC is running on automatic..........

Re: ListIcon drag to select multiple rows

Posted: Sun Sep 29, 2013 2:47 pm
by IdeasVacuum
...darn - if I add #PB_ListIcon_CheckBoxes

Code: Select all

IconGadget(0, 10, 10, 250, 230,"col 0", 100,#PB_ListIcon_FullRowSelect|#PB_ListIcon_MultiSelect|#PB_ListIcon_CheckBoxes)
....and either set to check or check and select:

Code: Select all

SetGadgetItemState(GetDlgCtrlID_(hwnd), lvh\iItem, #PB_ListIcon_Checked|#PB_ListIcon_Selected)
That works nicely, but the check boxes now won't toggle with a left-click :D

Re: ListIcon drag to select multiple rows

Posted: Tue Oct 01, 2013 6:59 am
by netmaestro
See if this is a bit closer to the goal, I'm assuming you want the drag to check the items as well as select them. If not, just remove the #PB_ListIcon_Checked flag from SetGadgetState:

Code: Select all

Procedure ListHandler(hwnd, msg, wparam, lparam)
  oldproc = GetProp_(hwnd, "oldproc")
  
  Select msg
    Case #WM_NCDESTROY
      RemoveProp_(hwnd, "oldproc")
           
    Case #WM_MOUSEMOVE
      If GetAsyncKeyState_(#VK_LBUTTON) & $8000
        With lvh.LVHITTESTINFO
          \pt\x = lparam&$FFFF
          \pt\y = lparam>>16
        EndWith
        SendMessage_(GadgetID(0), #LVM_HITTEST, 0, @lvh)
        If Not lvh\flags & #LVHT_ONITEMSTATEICON
          SetGadgetItemState(GetDlgCtrlID_(hwnd), lvh\iItem, #PB_ListIcon_Checked|#PB_ListIcon_Selected)
        EndIf
      EndIf
      
  EndSelect
  
  ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
  
EndProcedure


If OpenWindow(0, 0, 0, 270, 240, "ListIconGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 10, 10, 250, 230,"col 0", 100,#PB_ListIcon_FullRowSelect|#PB_ListIcon_MultiSelect|#PB_ListIcon_CheckBoxes)
  SetProp_(GadgetID(0), "oldproc", SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @ListHandler()))
  AddGadgetColumn(0, 1,"col 1",165)
  For a = 1 To 12
    AddGadgetItem (0, -1, "Item " + Str(a)+Chr(10)+"More Item "+Str(a)) ; define listview content
  Next
  SetActiveGadget(0)

  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: ListIcon drag to select multiple rows

Posted: Fri Oct 04, 2013 3:28 pm
by IdeasVacuum
Hi netmaestro

I only just noticed this response (wasn't expecting one) - it's a beautiful thing, thank you! 8)

Re: ListIcon drag to select multiple rows

Posted: Fri Oct 04, 2013 5:13 pm
by jassing
It's interesting that it checks the boxes if you drag & select -- but if you then unselect & drag/select it does not uncheck the boxes..