Double Click Question

Just starting out? Need help? Post your questions and find answers here.
tbohon
User
User
Posts: 42
Joined: Sat Nov 22, 2008 4:22 am
Location: Olympia, WA USA

Double Click Question

Post by tbohon »

The code below is supposed to put the doubleclicked item in the Listview into the StringGadget. Works fine.

However I can single click an item in the Listview and then double click anywhere on the form and it does the same thing.

Obviously not exactly what I was trying to achieve :?

So ... what am I missing? I tried to move the #WM_LBUTTONDBLCLK case inside of a Select Gadget but that didn't work and I'm stumped.

Thanks in advance for helping me learn more about this great language ... :D

Code: Select all

; PureBasic Visual Designer v3.95 build 1485 (PB4Code)

;- Window Constants
;
Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Listview_0
  #String_0
EndEnumeration


Procedure Main_Proc()
  If OpenWindow(#Window_0, 403, 270, 600, 300, "Listview DoubleClick Test",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
      ListViewGadget(#Listview_0, 40, 30, 140, 180)
      StringGadget(#String_0, 280, 30, 270, 30, "")
      
      AddGadgetItem(#Listview_0, -1, "First Item")
      AddGadgetItem(#Listview_0, -1, "Second Item")
      AddGadgetItem(#Listview_0, -1, "LAST ITEM!")
      
      SetGadgetState(#Listview_0, 0)
            
      Repeat
        
        Event.l = WaitWindowEvent()
        
        Select Event
				  Case #WM_LBUTTONDBLCLK
					  SetGadgetText(#String_0, GetGadgetText(#Listview_0))
					
				EndSelect

      Until Event = #PB_Event_CloseWindow 
   
  EndIf
EndProcedure

Main_Proc()            ; Program entry point
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Double Click Question

Post by srod »

Code: Select all

; PureBasic Visual Designer v3.95 build 1485 (PB4Code)

;- Window Constants
;
Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Listview_0
  #String_0
EndEnumeration


Procedure Main_Proc()
  If OpenWindow(#Window_0, 403, 270, 600, 300, "Listview DoubleClick Test",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
    ListViewGadget(#Listview_0, 40, 30, 140, 180)
    StringGadget(#String_0, 280, 30, 270, 30, "")
      
    AddGadgetItem(#Listview_0, -1, "First Item")
    AddGadgetItem(#Listview_0, -1, "Second Item")
    AddGadgetItem(#Listview_0, -1, "LAST ITEM!")
      
    SetGadgetState(#Listview_0, 0)
            
    Repeat
        
      Event = WaitWindowEvent()
      Select Event
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #Listview_0
              If EventType() = #PB_EventType_LeftDoubleClick
                SetGadgetText(#String_0, GetGadgetText(#Listview_0))
             EndIf
          EndSelect
      EndSelect
    Until Event = #PB_Event_CloseWindow 
  EndIf
EndProcedure

Main_Proc()            ; Program entry point
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Double Click Question

Post by ts-soft »

You have to use EventType:

Code: Select all

; PureBasic Visual Designer v3.95 build 1485 (PB4Code)

;- Window Constants
;
Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Listview_0
  #String_0
EndEnumeration


Procedure Main_Proc()
  If OpenWindow(#Window_0, 403, 270, 600, 300, "Listview DoubleClick Test",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
    ListViewGadget(#Listview_0, 40, 30, 140, 180)
    StringGadget(#String_0, 280, 30, 270, 30, "")
    
    AddGadgetItem(#Listview_0, -1, "First Item")
    AddGadgetItem(#Listview_0, -1, "Second Item")
    AddGadgetItem(#Listview_0, -1, "LAST ITEM!")
    
    SetGadgetState(#Listview_0, 0)
    
    Repeat
      
      Event.l = WaitWindowEvent()
      
      Select Event
          ;               Case #WM_LBUTTONDBLCLK
          ;                  SetGadgetText(#String_0, GetGadgetText(#Listview_0))
          ; 
          Case #PB_Event_Gadget
            Select EventGadget()
              Case #Listview_0
                Select EventType()
                  Case #PB_EventType_LeftDoubleClick
                    SetGadgetText(#String_0, GetGadgetText(#Listview_0))
                EndSelect
            EndSelect              
      EndSelect
      
    Until Event = #PB_Event_CloseWindow
    
  EndIf
EndProcedure

Main_Proc()            ; Program entry point
:x stephen is always faster :)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Double Click Question

Post by srod »

Thomas is always slower, always bringing up the rear! :)
I may look like a mule, but I'm not a complete ass.
tbohon
User
User
Posts: 42
Joined: Sat Nov 22, 2008 4:22 am
Location: Olympia, WA USA

Re: Double Click Question

Post by tbohon »

Thank you gentlemen ... greatly appreciate it.

As I said in a previous post, I'm having too much fun learning this language ... and after 45+ years developing software having fun is now my prime motivation. :mrgreen:

Best,

Tom
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Double Click Question

Post by srod »

Aye, Purebasic puts the fun into programming that's for sure.
I may look like a mule, but I'm not a complete ass.
Post Reply