views:

68

answers:

3

Hi all,

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...)

A: 

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.

VZ
Sorry that was a typo, it was meant to be wxListCtrl. I did try to capture the EVT_LEFT_UP and EVT_LEFT_DOWN events but these are never sent by the wxListCtrl so the code never runs.
Malvineous
You should be really using `EVT_LIST_ITEM_SELECTED` for this class and `wxGetMousePosition()` to get the mouse location (which won't be exactly the same as for the selection event but should be close enough).
VZ
A: 

Here are events I capture from my ListCtrl for left click and double click:

self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnListClick, self.ballotC)
self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnListDClick, self.ballotC)

You can see an example here.

Jeff
Thanks for the suggestion - these are the item selected and item activated events I refer to in my question, but when I use them the command "print event.GetPosition()" displays (0,0) for me regardless of where the click occurred, so I can't use them. Do you get coordinates from these events?
Malvineous
I don't know if you can get the position with those events. I suggest editing your question title and final sentence to make clear that you are looking for the coords of the left click.
Jeff
A: 
Mike Driscoll
Sorry, I can't see where you are printing the X and Y coordinates of the mouse click? Or any other way of detecting whether the mouse has been clicked on the image as opposed to anywhere else on the item.
Malvineous
See the onLeftClick method. Get the mouse position with "event.GetPosition()" and print it out with "print str(pos)"
Mike Driscoll