Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Developer
Posts: 60
Registered: ‎05-03-2013
My Device: Z10
My Carrier: Rogers
Accepted Solution

context menu on listview items in c++

Hello,

 

I just can't figure this out.  Can anyone tell me how to assign a context menu to each item in a listview?  Or direct me to documentation (the only one I can find is how to do it in QML but I don't use QML).

 

Thanks,

 

Matt M

Developer
Posts: 43
Registered: ‎12-16-2011
My Device: Torch 9800 & Playbook
My Carrier: Three

Re: context menu on listview items in c++

Hi Matt,

 

To accomplish this I created a context menu within the constructor of my custom listitem class.

regards

Daniel - Neurocode
If my posts help, please click the Like button.

gymChronicles - helping you to keep motivated
Regular Contributor
Posts: 54
Registered: ‎02-15-2013
My Device: Z10

Re: context menu on listview items in c++

There is very good sample app Cookbooks using C++ for listview

Developer
Posts: 60
Registered: ‎05-03-2013
My Device: Z10
My Carrier: Rogers

Re: context menu on listview items in c++

I'm not currently using custom list items which is my problem I think.  I'd rather not have to but will if I need to

Developer
Posts: 43
Registered: ‎12-16-2011
My Device: Torch 9800 & Playbook
My Carrier: Three

Re: context menu on listview items in c++

Do you need to have an individual context menu item for each list item?  or could you make do with assigning a context menu to the listview and when a context menu item is selected, work out which list item was selected in the list view?

regards

Daniel - Neurocode
If my posts help, please click the Like button.

gymChronicles - helping you to keep motivated
Developer
Posts: 60
Registered: ‎05-03-2013
My Device: Z10
My Carrier: Rogers

Re: context menu on listview items in c++

What I'm doing is that I have a sql database from which I grab a list of items that I pass to my groupdatamodel.  The model goes into the listview.

 

What I'd love to do is add a context menu to each item in the listview but I can't figure out how other than to make my own list items which I'd rather not do.  The reason for this is that I want the use to be able to delete items by long holding them.  I'd also like to offer edit in the same menu.

Developer
Posts: 43
Registered: ‎12-16-2011
My Device: Torch 9800 & Playbook
My Carrier: Three

Re: context menu on listview items in c++

In such a case I would recommend assigning the context menu to the listview.  The listview has signals to let you know which item was selected.  And if you receive a signal from the context menu item, for example, to delete an item you can remove the one (or multiple) indicated by the listview.

 

Here are some links that will help guide you:

List view selection

The examples are in QML, but the idea is the same in c++.

regards

Daniel - Neurocode
If my posts help, please click the Like button.

gymChronicles - helping you to keep motivated
Developer
Posts: 60
Registered: ‎05-03-2013
My Device: Z10
My Carrier: Rogers
Developer
Posts: 60
Registered: ‎05-03-2013
My Device: Z10
My Carrier: Rogers

Re: context menu on listview items in c++

That link for QML is what's had me confounded.  It's easy to add them in QML because of the itemcomponent but c++ doesn't use it.

Developer
Posts: 43
Registered: ‎12-16-2011
My Device: Torch 9800 & Playbook
My Carrier: Three

Re: context menu on listview items in c++

[ Edited ]

Indeed, so you'll need to do the work yourself, store which item(s) were selected and then respond according to which context action was chosen.

regards

Daniel - Neurocode
If my posts help, please click the Like button.

gymChronicles - helping you to keep motivated