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
Contributor
Posts: 16
Registered: ‎05-26-2013
My Device: Z10
My Carrier: UAE DU

select / unselect an item in ListView

Hi,

 

 I am trying to have a multiselect ListView, I made the following ListView, what I need is when the item is selected, if it's already selected I need to deselect, how to do that?

 

In the OnTriggered, I tried to capture the data item and check if selected already, but that fails also.

 

            ListView {

 

                id: contactsListViewID

                objectName: "contactsListViewObj"

 

                dataModel: _contactsModel

 

                onTriggered: {

                        select(indexPath);

                }

 

                onSelectionChanged: {

                    // The status text of the multi-select handler is updated to show how

                    // many items are currently selected.

                    if (selectionList().length > 1) {

                        contactsBar.title = selectionList().length + " items selected";

                    } else if (selectionList().length == 1) {

                        contactsBar.title = "1 item selected";

                    } else {

                        contactsBar.title = "None selected";

                    }

                }

 

                listItemComponents: ListItemComponent {

                    type: "item"

                    

                      StandardListItem {

                        title: ListItemData.name

                        description: ListItemData.email

                      }

 

                }

            }

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: select / unselect an item in ListView

Instead of using the select() function, perhaps you'd be better served by the toggleSelection() function?

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Contributor
Posts: 16
Registered: ‎05-26-2013
My Device: Z10
My Carrier: UAE DU

Re: select / unselect an item in ListView

Thank you Peter, that does it Smiley Happy

 

May I ask you where to get the API of all Cascades related functions? I am searching in http://developer.blackberry.com/cascades/reference/ but this is all mostly C++.

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: select / unselect an item in ListView

On the page you have referenced, left hand side, ther si a pull down entitles "Show".  Using that you can select C++ or Cascades or both.  Does that help?

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: select / unselect an item in ListView

My personal way to get to the docs is to google "cascades some-term" and it generally hits the right API page immediately. For example, "cascades listview" does the job in this case.

The page you mentioned is a valid top-level place to start though, if you want. The ListView docs are under User Interface, List, ListView.

To find things like toggleSelection(), which is admittedly rather buried way down the bottom of that page, there's no real substitute for ongoing "practice"... and lots of reading and re-reading. I've read the ListView page at least a dozen times at this point, probably twice that. Only way I know of to be able to find the things I need when I finally need them.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 21
Registered: ‎12-18-2012
My Device: Playbook ,Dev Alpha C, Limited Edition Z10
My Carrier: Airtel

Re: select / unselect an item in ListView

[ Edited ]

Use multiSelectHandler and multiSelect Action Item.something like this.

ListView {

id: contactsListViewID
objectName: "contactsListViewObj"

dataModel: _contactsModel

 

 

listItemComponents: ListItemComponent {

                    type: "item"

                    

                      StandardListItem {

                        id:listItem

                        title: ListItemData.name

                        description: ListItemData.email

 

                      

                        contextActions: [
                                        ActionSet {

                                                        

                                                MultiSelectActionItem {
                                                                      multiSelectHandler: listItem.ListItem.view.multiSelectHandler

                                                                      onTriggered: {
                                                                                     multiSelectHandler.active;
                                                                      }

                                                 }

                                        }

                         ] 

 

                       }

                multiSelectHandler {
                                      status: qsTr("None selected") 

                 //actions that uses multiselect

                }

                onSelectionChanged:{

                                    updateMultiStatus();

                 }

               

                 

                  function updateMultiStatus() {

                                 // The status text of the multi-select handler is updated to show how
                                 // many items are currently selected.
                                 if (selectionList().length > 1) {
                                                     multiSelectHandler.status = selectionList().length + qsTr(" items selected");
                                 } else if (selectionList().length == 1) {
                                                      multiSelectHandler.status = qsTr("1 item selected");
                                } else {
                                                       multiSelectHandler.status = qsTr("None selected");
                                 }
                     }

}

Highlighted
Contributor
Posts: 16
Registered: ‎05-26-2013
My Device: Z10
My Carrier: UAE DU

Re: select / unselect an item in ListView

Thank you all for the support.