Share your advanced knowledge/code with the community.
User avatar
Peter
 
Posts: 546
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

SetGadgetStateEx() for ListViewGadget() and ListIconGadget()

by Peter Tue Sep 04, 2018 12:40 pm

Hello,

until it is fixed, you can use SetGadgetStateEx() to scroll automatically to the selected Item for ListViewGadget() and ListIconGadget():

Code: Select all
EnableExplicit

Procedure SetGadgetStateEx(Gadget, SelectedItem)
 
  Select GadgetType(Gadget)
     
    Case #PB_GadgetType_ListView, #PB_GadgetType_ListIcon
     
      ! setTimeout( function() {
     
      SetGadgetState(Gadget, SelectedItem)
     
      ! if (($(spider_GadgetID(v_gadget).div).find(".dgrid-selected")).length > 0) {
      !   spider_GadgetID(v_gadget).gadget.scrollTo({x:0,y:$(spider_GadgetID(v_gadget).div).find(".dgrid-selected").position().top});
      ! } else {
      !   spider_GadgetID(v_gadget).gadget.scrollTo({x:0,y:0});
      ! }
     
      ! }, 10);
     
    Default
     
      Debug "Unsupported Gadget"
     
  EndSelect
 
EndProcedure

Enumeration
  #Window
  #ListViewGadget
  #ListIconGadget
EndEnumeration

Define Counter

OpenWindow(#Window, 0, 0, 510, 140, "ScrollIntoView", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

; ######################
; # ListViewGadget
; ######################

ListViewGadget(#ListViewGadget, 10, 10, 250, 120)

For Counter = 1 To 12
  AddGadgetItem (#ListViewGadget, -1, "Line " + Str(Counter) + " of the ListViewGadget")
Next

SetGadgetStateEx(#ListViewGadget, 10)

; ######################
; # ListIconGadget
; ######################

ListIconGadget(#ListIconGadget, 260, 10, 250, 120, "First Column", 200)

For Counter = 1 To 12
  AddGadgetItem (#ListIconGadget, -1, "Line " + Str(Counter) + " of the ListIconGadget")
Next

SetGadgetStateEx(#ListIconGadget, 10)


Greetings ... Peter
Dirk Geppert
 
Posts: 83
Joined: Fri Sep 22, 2017 7:02 am

Re: SetGadgetStateEx() for ListViewGadget() and ListIconGadg

by Dirk Geppert Tue Sep 04, 2018 1:49 pm

Thank you Peter!
Return to Tricks 'n' Tips

Who is online

Users browsing this forum: No registered users and 0 guests