Listview problem

Just starting out? Need help? Post your questions and find answers here.
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

Listview problem

Post by Columbo »

I have set up a Listview and a button where the user can highlight an item in the list view and then click the button to jump to a procedure based upon the item selected and it works ok.

I can set it up without the button and have the user double click an item in the Listview and have it jump to a procedure based upon the item double clicked and that works ok.

My problem is that I want to give the user the option of clicking on a button or double clicking an item but I can’t seem to accomplish this. Can anyone show me a the best way to achieve this on Window OS?

Thanks
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Listview problem

Post by StarBootics »

This code should do the tricks :

Code: Select all

Procedure ProcedureToRun()
  
  Debug GetGadgetText(0)
  
EndProcedure


If OpenWindow(0,0,0,400,300,"ListViewGadget",#PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  ListViewGadget(0,5,5,250,120)
  For a=1 To 12
    AddGadgetItem (0,-1,"Elément "+Str(a)+" de la boîte à liste")   ; défini le contenu de la boîte de liste
  Next
  SetGadgetState(0,9)    ; sélectionne le dixième élément (la numérotation commmence à 0)
  
  ButtonGadget(1, 5, 130, 250, 34, "The Button")
  
  Repeat
    
    Select WaitWindowEvent()
        
      Case #PB_Event_Menu
        
        Select EventMenu()
            
        EndSelect
        
      Case #PB_Event_Gadget
        
        Select EventGadget()
            
          Case 0
            If EventType() = #PB_EventType_LeftDoubleClick
              ProcedureToRun()
            EndIf
            
          Case 1
            ProcedureToRun()
            
        EndSelect
        
      Case #PB_Event_CloseWindow
        
        Select EventWindow()
            
          Case 0
            Break
            
          Default
            CloseWindow(EventWindow())
            
        EndSelect
        
    EndSelect
    
  ForEver
  
  End
  
EndIf
Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Micoute
User
User
Posts: 28
Joined: Sat Jun 22, 2013 4:06 pm
Location: La Mézière FRANCE

Re: Listview problem

Post by Micoute »

Merci pour le partage
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

Re: Listview problem

Post by Columbo »

Merci beaucoup. Très apprécié.
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: Listview problem

Post by kpeters58 »

Or, if you are a friend of binding events:

Code: Select all

Enumeration
  #Window
  #Listview
  #Button
EndEnumeration

Procedure ProcedureToRun(Originator.s)
  Debug GetGadgetText(#Listview) + " " + Originator
EndProcedure

Procedure ButtonClick()
  ProcedureToRun("Button")
EndProcedure

Procedure ListviewClick()
  ProcedureToRun("Listview")
EndProcedure

Procedure WindowClose()
  CloseWindow(EventWindow())
EndProcedure


If OpenWindow(#Window, 0, 0, 400, 300, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  ListViewGadget(#Listview, 5, 5, 250, 120)
  For a = 1 To 12
    AddGadgetItem (#Listview, -1, "Elément "+Str(a)+" de la boîte à liste")   ; défini le contenu de la boîte de liste
  Next
  SetGadgetState(#Listview, 9)    ; sélectionne le dixième élément (la numérotation commmence à 0)
  ButtonGadget(#Button, 5, 130, 250, 34, "The Button")
  ;
  BindGadgetEvent(#Button, @ButtonClick())
  BindGadgetEvent(#Listview, @ListviewClick(), #PB_EventType_LeftDoubleClick)
  BindEvent(#PB_Event_CloseWindow,  @WindowClose(), #Window)
    
  Repeat
    Select WaitWindowEvent()
    EndSelect
  ForEver
EndIf
PB 5.73 on Windows 10 & OS X High Sierra
Post Reply