[SOLVED] Move to line position in a listiconGadget?

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Addict
Addict
Posts: 1086
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

[SOLVED] Move to line position in a listiconGadget?

Post by Randy Walker »

I found this and works great for for EditorGadget:
viewtopic.php?p=441542#p441542
and tried to adapt it to ListIconGadget but could not make it work. How do I jump to a particlar line? Here I just want to jump to end of the list:

Code: Select all

  If OpenWindow(0, 0, 0, 230, 120, "Eventtypes example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
     ListIconGadget(1, 10, 10, 150, 100, "ListIcon", 140, #PB_ListIcon_GridLines) 
     For a = 1 To 14 
       AddGadgetItem(1, -1, "Line "+Str(a)) 
     Next
     ;How do I jump to line #14, end of the list ?
     Repeat
       Event = WaitWindowEvent()
     Until Event = #PB_Event_CloseWindow
  EndIf
Would be really nice to know how to jump to any line too.
Thanks!!
Last edited by Randy Walker on Sun Sep 21, 2025 12:09 am, edited 1 time in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4965
Joined: Sun Apr 12, 2009 6:27 am

Re: Move to line position in a listiconGadget?

Post by RASHAD »

Hi Randy
Using native commands

Code: Select all

Procedure SelectItem(gadget,item)
  SetGadgetState(gadget,item)
  SetGadgetItemState(gadget,item,1)
  SetActiveGadget(gadget)
EndProcedure

If OpenWindow(0, 0, 0, 300, 300, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 10,10, 280, 200, "Name", 200, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
  
  For i = 0 To 1000
    AddGadgetItem(0, -1, Str(i))
  Next
   
  SelectItem(0,150)
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = 1
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0

        EndSelect
    EndSelect
  Until Quit = 1            
EndIf
For Windows

Code: Select all

Procedure SelectRow(gadget,index)
  Row_H = SendMessage_(GadgetID(gadget), #LVM_GETITEMSPACING, 1, 0) >> 16 
  SendMessage_(GadgetID(0), #LVM_SCROLL, 0,-CountGadgetItems(gadget)*Row_H)  
  SetGadgetItemState(gadget,index,#PB_ListIcon_Selected)
  SetFocus_(GadgetID(gadget))
  SendMessage_(GadgetID(0), #LVM_SCROLL, 0,index*Row_H)
EndProcedure

LoadFont(0,"Arial",12)
If OpenWindow(0, 0, 0, 640, 350, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0,  10,  10, 620, 280, "Column 0", 400,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
  SetGadgetFont(0,FontID(0))
  AddGadgetColumn(0, 1, "Column 1" , 200)
  For x = 0 To 100
    AddGadgetItem(0, x, "Item "+Str(x)+Chr(10)+"Item "+Str(x))
  Next    
EndIf
SelectRow(0,80)
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
      EndSelect
  EndSelect
  
Until Quit = 1
Egypt my love
Randy Walker
Addict
Addict
Posts: 1086
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Move to line position in a listiconGadget?

Post by Randy Walker »

PERFECT! Once again, You are the man RASHAD. THANKS!!!! ! ! !
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Axolotl
Addict
Addict
Posts: 865
Joined: Wed Dec 31, 2008 3:36 pm

Re: [SOLVED] Move to line position in a listiconGadget?

Post by Axolotl »

Windows only:

Code: Select all

SendMessage_(GadgetID(Gadget), #LVM_ENSUREVISIBLE, Index, #False) ; lParam ==> #True if partially visible is okay. 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Post Reply