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 Contributor
skbb10
Posts: 9
Registered: ‎07-12-2013
My Device: z10,q10
My Carrier: fdf

unable to add pickerItemComponent dynamically into picker

Hi,

      I am trying to implement picker widget.My requirement is  to add pickerItemComponent into pickerItemComponents Property with dynamically.As pickerItemComponents  is an array,trying to add into it after creating pickerItemComponent object.please find the below given code snippet.This code giving error with unable to createobject.

 

//pickerItemComponent.qml//

import bb.cascades 1.0
PickerItemComponent {
    type: "item1"
    property alias pickerText:labl.text;
    content: Container {
        Label {
            id:labl

        }
    }
}

//main.qml

 var pickerComponent = Qt.createComponent("pickerItemComponent.qml");
                var pickerItem = pickerComponent.createObject();
                pickerItem.pickerText = "pickertest";
                picker.pickerItemComponents[pickerItem];

Any suggestion would be great help for me.

 

Thanks,

Sk

Please use plain text.
Developer
sorout2009
Posts: 104
Registered: ‎08-23-2012
My Device: Blackberry Z10
My Carrier: TATA DOCOMO

Re: unable to add pickerItemComponent dynamically into picker

For inserting data dynamically, you need to define its data model like

 

Picker {
id: picker
dataModel: GroupDataModel {
id: pickermodel
grouping: ItemGrouping.None
}
pickerItemComponents: [
PickerItemComponent {
Container {
Label {
text: pickerItemData.name
}
}
}
]
}

 

 

Now for inserting data, you can insert data as in ListView like below

 

picker.dataModel.insert(data_list)

 

May be this will help you.

 

Still facing problem, let me know.

Dharmender Singh
Please use plain text.
New Contributor
skbb10
Posts: 9
Registered: ‎07-12-2013
My Device: z10,q10
My Carrier: fdf

Re: unable to add pickerItemComponent dynamically into picker

Thanks for quick reply.can't we use arraydata model?

Please use plain text.
Developer
sorout2009
Posts: 104
Registered: ‎08-23-2012
My Device: Blackberry Z10
My Carrier: TATA DOCOMO

Re: unable to add pickerItemComponent dynamically into picker

Yes, you can use ArrayDataModel.
Just try it and still have problem, I am here to help you.

Press like if this solved your problem.
Dharmender Singh
Please use plain text.
New Contributor
skbb10
Posts: 9
Registered: ‎07-12-2013
My Device: z10,q10
My Carrier: fdf

Re: unable to add pickerItemComponent dynamically into picker

 

Hi sorout,

   Sorry for late response .Meanwhile got interrupted because of some other activity.

Following given code i am using whatever you suggested but still facing same problem means empty picker widget appears with title only(no data).

 

Picker {
            id: picker
            title: "Picker title"
            rootIndexPath: []
            dataModel: ArrayDataModel {
            }

            pickerItemComponents: [
                PickerItemComponent {
                    type: "item1"
                    content: Container {
                        Label {
                            text: pickerItemData.name
                        }
                    }
                }
            ]

            onCreationCompleted: {
                console.log("Picker Item Component created..");
                for (var i = 0; i < 25; i ++) {
                    var mystr = "Name" + i;
                    var data = {
                        "name": mystr
                    }
                    picker.dataModel.insert(i,data);
                }
            }
           

If anything wrong in above code please let me know it would great help for me.

Thanks

sk

Please use plain text.
Developer
LoganSix
Posts: 265
Registered: ‎01-02-2011
My Device: Z30, PlayBook
My Carrier: AT&T

Re: unable to add pickerItemComponent dynamically into picker

Did you get this code working?

 

I keep getting the error

Picker: incorrect model, wrong columns number:  0 

 And no data shows up in the picker.

_________________
Meetup for BlackBerry 10
Meetup Search Tool - not available at the moment
Please use plain text.