[SOLVED] How to get the right click event from a listview?

Just starting out? Need help? Post your questions and find answers here.
avatar
User
User
Posts: 35
Joined: Fri Apr 16, 2010 11:43 am

[SOLVED] How to get the right click event from a listview?

Post by avatar »

I have searched this forum for the captioned query.
Somebody said that there is a Window API for it.

Could anybody help me with example codes?
Last edited by avatar on Thu Apr 22, 2010 4:20 am, edited 1 time in total.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: How to get the right click event from a listview?

Post by c4s »

What about...

Code: Select all

Select WaitWindowEvent()
	Case #PB_Event_Gadget
		Select EventGadget()
			Case #ListView
				If EventType() = #PB_EventType_RightClick
					DisplayPopupMenu(#ListViewMenu, WindowID(#Window))
				EndIf

;[...]
:?:
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
avatar
User
User
Posts: 35
Joined: Fri Apr 16, 2010 11:43 am

Re: How to get the right click event from a listview?

Post by avatar »

Already tried
and
the PB manual says not support right-click in ListView

i am now considering recoding to change to ListIcon
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: How to get the right click event from a listview?

Post by c4s »

Ah sorry I missed that.
Anyway you can make a ListIconGadget() look and behave like a ListViewGadget() so it shoulfn't be a problem.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: How to get the right click event from a listview?

Post by ts-soft »

Code: Select all

Procedure WinCB(hWnd, uMsg, wParam, lParam)
  Protected result = #PB_ProcessPureBasicEvents
  
  Select uMsg
    Case #WM_CONTEXTMENU
      If GetActiveGadget() = 0
        Debug "Contextmenu on ListView"
      EndIf
  EndSelect
  
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 270, 140, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListViewGadget(0, 10, 10, 250, 120)
  For a = 1 To 12
    AddGadgetItem (0, -1, "Item " + Str(a) + " of the Listview")
  Next
  SetGadgetState(0, 9)
  SetWindowCallback(@WinCB())
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf


User avatar
skywalk
Addict
Addict
Posts: 4242
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: How to get the right click event from a listview?

Post by skywalk »

Very helpful ts-soft! :)

I was trying callback and failed on Case #WM_RBUTTONDOWN ?

srod's EasyVent works also. But, this is sufficient to allow a popup menu or some such on a simple ListView.
Last edited by skywalk on Sun Nov 25, 2012 8:55 pm, edited 1 time in total.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: How to get the right click event from a listview?

Post by ts-soft »

Is only useful on listview and editorgadget.
donSHAYA
User
User
Posts: 95
Joined: Wed Mar 25, 2009 9:57 am

Re: How to get the right click event from a listview?

Post by donSHAYA »

Does this work on all gadgets? I don't know:

Code: Select all

Procedure RightClick(#Window, #Gadget, Event)
If Event = #WM_RBUTTONDOWN
If WindowMouseX(#Window) > GadgetX(#Gadget) And WindowMouseX(#Window) < GadgetX(#Gadget) + GadgetWidth(#Gadget)
If WindowMouseY(#Window) > GadgetY(#Gadget) And WindowMouseY(#Window) < GadgetY(#Gadget) + GadgetHeight(#Gadget)
; [Bla bla bla...} or
; ProcedureReturn 1
EndIf
EndIf
EndIf

EndProcedure

#MainWin = 0
#ListViewG = 0
OpenWindow(#MainWin, #PB_Ignore, #PB_Ignore, 200, 200, "Test", #PB_Window_ScreenCentered)
ListViewGadget(#ListView, 5, 5, 100, 100)

Repeat

Evt = WaitWindowEvent()

RightClick(#MainWin, #ListViewG, Evt)

Until Evt = #PB_Event_CloseWindow
avatar
User
User
Posts: 35
Joined: Fri Apr 16, 2010 11:43 am

Re: How to get the right click event from a listview?

Post by avatar »

Thank you all for the input.
User avatar
Shardik
Addict
Addict
Posts: 2068
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [SOLVED] How to get the right click event from a listvie

Post by Shardik »

Unfortunately ts-soft's example contains a bug: If your first action is a right click, this
right click will not be detected. Only after a first left mouse click all following right clicks
are reliably detected. In order to solve this problem you should compare the wParam
with the handle of the ListViewGadget to make sure that the right click occured inside the
ListViewGadget:

Code: Select all

Procedure WinCB(hWnd, uMsg, wParam, lParam)
  Protected result = #PB_ProcessPureBasicEvents
 
  Select uMsg
    Case #WM_CONTEXTMENU
      If wParam = GadgetID(0)
        Debug "Contextmenu on ListView"
      EndIf
  EndSelect

  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 270, 140, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListViewGadget(0, 10, 10, 250, 120)
  For a = 1 To 12
    AddGadgetItem (0, -1, "Item " + Str(a) + " of the Listview")
  Next
  SetGadgetState(0, 9)
  SetWindowCallback(@WinCB())
 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: [SOLVED] How to get the right click event from a listvie

Post by ts-soft »

In wParam is the hwnd, thx.
I have tested with lParam :oops:
Post Reply