Page 1 of 1

Listview problem

Posted: Mon Apr 29, 2019 4:13 am
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

Re: Listview problem

Posted: Mon Apr 29, 2019 5:05 am
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

Re: Listview problem

Posted: Mon Apr 29, 2019 7:50 am
by Micoute
Merci pour le partage

Re: Listview problem

Posted: Mon Apr 29, 2019 3:23 pm
by Columbo
Merci beaucoup. Très apprécié.

Re: Listview problem

Posted: Mon Apr 29, 2019 3:51 pm
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