ListIcon drag to select multiple rows

Windows specific forum
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

ListIcon drag to select multiple rows

Post by IdeasVacuum »

ListIconGadget() Drag mouse to select multiple rows, as you can with a ListView?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: ListIcon drag to select multiple rows

Post 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
BERESHEIT
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: ListIcon drag to select multiple rows

Post by IdeasVacuum »

Woo, thanks netmaestro! 8)
I forgot myself a long time ago, the PC is running on automatic..........
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: ListIcon drag to select multiple rows

Post 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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: ListIcon drag to select multiple rows

Post 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
BERESHEIT
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: ListIcon drag to select multiple rows

Post by IdeasVacuum »

Hi netmaestro

I only just noticed this response (wasn't expecting one) - it's a beautiful thing, thank you! 8)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: ListIcon drag to select multiple rows

Post 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..
Post Reply