Right mouse click on a listbox?

Hi,

If possible, how do I bind a right mouse click event to a selected item on the listbox?

Statement Of Confidentiality:

This electronic message transmission, and all attachments, contains information from Extron Electronics which is confidential and privileged. The information is for the exclusive viewing or use of the intended recipient. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this electronic transmission in error, please notify the sender immediately by a “reply to sender only” message and destroy all electronic and hard copies of the communication, including attachments.

Hello,

Hi,

If possible, how do I bind a right mouse click event to a selected item on the listbox?

A ListBox holds a list of strings so you can’t bind events directly to the strings in the list. You should however be able to bind EVT_RIGHT_UP or EVT_CONTEXT_MENU to the ListBox itself and then just call MyListBox.GetSelection() to get the currently selected item in the handler.

i.e)

self._lbox.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)

def OnRightUp(self, evt):

print “Right Click:”, self._lbox.GetSelection()

You may want to look at using a ListCtrl with LC_LIST style instead of a ListBox as I don’t think right clicking on an item in a ListBox will set the selection where as in a ListCtrl it will.

Cody

···

On Thu, Dec 4, 2008 at 12:26 PM, Qui Le qle@extron.com wrote:

Qui Le wrote:

Hi,
If possible, how do I bind a right mouse click event to a selected item on the listbox?

wx.ListBox doesn't have the ability to reliably let you know which items are at the position where the mouse event happened. Using wx.ListCtrl might be a better choice.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!