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
Developer
steve8820
Posts: 78
Registered: ‎04-04-2013
My Device: BB10 Dev Alpha Simulator

How to change property of a control inside a listview?

[ Edited ]

Hi,

 

I have a listview with a container inside with labels and checkbox inside. I want to make the checkbox to be checked when i select the row. Is this possible? Below are my codes.

 

ListView {
                    id: listview1
                    dataModel: XmlDataModel {
                        id: accListXml
                        source: "../Model/account.xml"
                    }
                    listItemComponents: [
                        ListItemComponent {
                            type: "account"
                            Container {
                                background: Color.LightGray
                                topPadding: 5.0
                                leftPadding: 5.0
                                bottomPadding: 5.0
                                rightPadding: 5.0
                                rightMargin: 5.0
                                Container {
                                    id: accInnerContainer
                                    layout: StackLayout {

                                    }
                                    background: Color.White
                                    ImageView {
                                        id: imgAcc
                                        imageSource: ListItemData.imagefile
                                        preferredHeight: 200.0
                                    }
                                    Label {
                                        id: lblAccName
                                        text: ListItemData.accname
                                        multiline: true
                                    }
                                    Label {
                                        id: lblAccNo
                                        text: ListItemData.accno
                                    }
                                    CheckBox {
                                        id: cbAcc
                                        horizontalAlignment: HorizontalAlignment.Center
                                    }
                                }
                            }            
                        }
                    ]       
                    horizontalAlignment: HorizontalAlignment.Fill
                    verticalAlignment: VerticalAlignment.Fill
                    layout: StackListLayout {
                        orientation: LayoutOrientation.LeftToRight

                    }
                }

 

 

Regards,

Steve Chan
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: How to change property of a control inside a listview?

Hi,
This can be done by binding CheckBox's state to a field in dataModel and updating the field in onTriggered.

Important: ListItemData is returning a copy of item. After updating the field, replace the entire item in model at chosen indexPath. Something like:
var data = ListItemData
data.myCheckboxState = ...
idOfTopItemInListItemComponent.listItem.view.dataModel.updateItem(indexPath, data)

XMLDataModel is very limited and doesn't have any methods to update the model. ArrayDataModel or GroupDataModel can be used instead. You'll have to implement the parsing to fill it with XML data initially.

Andrey Fidrya, @zmeyc on twitter
Regular Contributor
erAjayGoyal
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800

Re: How to change property of a control inside a listview?

Yes,it can be possible, in Triggered() get indexPath and using that u can do whatever u wanted.

Developer
steve8820
Posts: 78
Registered: ‎04-04-2013
My Device: BB10 Dev Alpha Simulator

Re: How to change property of a control inside a listview?

Thanks for the reply. But I'm a beginner here so I'm not quite understand it. Did you mean that I need to assign a random ID into each row in my xml to represent them and use the indexPath you mentioned to get the ID from xml to find the checkbox?
Regards,

Steve Chan