develooper Front page | perl.wxperl.users | Postings from February 2013

Re: Getting information from EVT_LIST_ITEM_RIGHT_CLICK

Thread Previous | Thread Next
Mark Dootson
February 5, 2013 03:01
Re: Getting information from EVT_LIST_ITEM_RIGHT_CLICK
Message ID:

On 31/01/2013 22:41, Dave Hayes wrote:
> Hello. I'm trying to get the text, column, and item index on a right
> click in a Wx::ListCtrl. The item index works perfectly. However, I
> can't seem to get any other information. Here's a very abbreviated idea
> of what I am doing:

I can answer this by pulling a couple of 'rabbits out of a hat' in the 
form of undocumented method calling and some extra code for none wxMSW 

The method $event->GetPoint() will return the mouse position.

The method $listctrl->HitTest($point) actually returns three items, the 
third of which is the subitem, or column index.

The method $listctrl->GetItem actually accepts two params, the second 
being the column number (default 0).

So to get the column text that was clicked the following ought to work:

my $point = $event->GetPoint();
my $listctrl = $event->GetEventObject;
my($itemindex, $flags, $subitemindex) = $listctrl->HitTest($point);
my $text = $listctrl->GetItem($itemindex, $subitemindex)->GetText;
print qq(Right clicked text: $text\n);

Alas, the third return item from $listctrl->HitTest is only implemented 
on Windows, so we need a separate method to determine the column clicked 
on wxGTK for example. It is quite simple to implement - an 
implementation is contained in the attached code.

Hope it helps.



Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About