Search code examples
wxpythonwxwidgets

wxWidgets: How to catch left-click on wxListCtrl?


I want to add checkboxes to a wxListCtrl, and this works fine except there doesn't appear to be an EVT_LIST_ITEM_CLICK or EVT_LIST_ITEM_LEFT_CLICK event to catch when the mouse is clicked on the item so the image can be toggled. There are events for right and middle click, just not left click - which means you have to middle or right click to tick/untick the items in the list.

Does anyone know whether there is a left-click event you can use? I tried the item selected and item activated events, but these don't report the pixel location of the event, so I can't use them to figure out whether the image was the part of the item clicked.

I was basing the code on some at the the wxWidgets wiki, except they override the wxListCtrl class which I want to avoid for simplicity. I'm also aware of wxGrid and other alternate controls, but none of them are as quick as the wxListCtrl (and the wxGrid checkboxes look awful too.)

So, does anyone know how you can get the coordinates of left-clicks in a wxListCtrl?

EDIT: Sorry, wxListCtrl not wxListGrid (was thinking too hard about wxGrid...)


Solution

  • This is the first time ever I hear about wxListGrid so I don't know what is it capable of. However in general you can always catch the low level mouse click events (e.g. EVT_LEFT_UP) and find the item underneath the mouse position.