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
New Developer
Posts: 16
Registered: ‎12-16-2010
My Device: Not Specified
Accepted Solution

ListView checkBox

[ Edited ]

HI,

 

So  I have a ListView with a ListItemComponent that has a custom row.

Inside that custom row I have a  checkbox   that I can click without  triggering the row selection.

How can I find out what row has been clicked (or the information that is there on the row)

Can this be done with qml?

 

   Container {
        
        ListView {
            id: List
            layout: StackListLayout {
                headerMode: ListHeaderMode.Sticky
            }

            dataModel: dataModel
            listItemComponents: [
                ListItemComponent {
                    type: "item"
                    CustomItem {

                           //a custom item with a check box that can be checked on/off

                                 ......
                                                }

 

 

 

thanks guys Smiley Wink

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: ListView checkBox

Hi! It should be possible.

 

- Create CheckBox and make sure onCheckedChanged is called.

 

CheckBox {
  id: checkboxId
  text: "Checkbox title"
  onCheckedChanged: {
    console.log("onCheckedChanged called");
  }
}

 

 

- In onCheckedChanged handler get the row number from ListItem.indexPath. ListItem is available only on the root element of ListItemComponent. See this page for details on accessing the root from child elements:

https://developer.blackberry.com/cascades/reference/bb__cascades__listview.html

 

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 91
Registered: ‎09-25-2012
My Device: bb10 alpha
My Carrier: free

Re: ListView checkBox

The best way is to add the checked Value directly in your model. Otherwise, you will lost you checked during ListView refresh. So, if you are using an ArrayDataModel with a "checked" key property  : 

 

So in your CheckBox {

 

onChecked : ListItemData.checked = false;

 

}

 

 

a lover of Qt
Highlighted
New Developer
Posts: 16
Registered: ‎12-16-2010
My Device: Not Specified

Re: ListView checkBox

how do you add key values in a model ? and then be able to acces them with  ListItemData.checked (or something like this ?

 

Could you do something like this

 

  dataModel:ArrayDataModel {
                id: arrayModel
                property bool checked;              <-------------------------------key value
....................

....................

.....................

}

 

PS:I know that you add the keys when you insert the data in the model,but is there another way?