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

Posts: 23
Registered: ‎10-08-2012
My Device: 9800
My Carrier: vodafone

ListView of CheckBoxes with C++

Hi, I want to make a listview of Checkboxes, but the no checkboxes appeared but labels only

here is my qml

import bb.cascades 1.0
Page {
    content: Container {    
        // Create a ListView that uses an XML data model
        ListView {
            id: listview
            // Add appearance definitions for the list items using the
            // listItemComponents list
            listItemComponents: [
                // The first ListItemComponent defines how "header" items
                // should appear. These items use a Label.
                ListItemComponent {
                    type: "header"
                    Label {
                        text: ListItemData.title
                        // Apply a text style to create a large, bold font with
                        // a specific color
                        textStyle {
                            base: SystemDefaults.TextStyles.BigText
                            fontWeight: FontWeight.Bold
                            color: Color.create ("#7a184a")
                // The second ListItemComponent defines how "listItem" items
                // should appear. These items use a Container that includes a
                // CheckBox and a Label.
                ListItemComponent {
                    type: "listItem"
                    Container {
                        layout: StackLayout {
                            orientation: LayoutOrientation.LeftToRight
                        CheckBox {
                            // Determine whether the CheckBox should be checked
                            // according to a value in the data model
                            checked: ListItemData.checked
                        Label {
                            text: ListItemData.title
                            // Apply a text style to create a title-sized font
                            // with normal weight
                            textStyle {
                                base: SystemDefaults.TextStyles.TitleText
                                fontWeight: FontWeight.Normal
                    } // end of Container
                } // end of second ListItemComponent
            objectName: "listview"
            // end of listItemComponents list
        } // end of ListView
    } // end of Container
} // end of Page

 and here is my cpp

// Default empty project template
#include "MyEx.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/listView>
#include <bb/cascades/ArrayDataModel>
#include <bb/cascades/Page>

using namespace bb::cascades;

MyEx::MyEx(bb::cascades::Application *app) :
		QObject(app) {
	QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
	Page *page = qml->createRootObject<Page>();
	ListView *listView = page->findChild<ListView*>("listview");
	ArrayDataModel *model = new ArrayDataModel;

I want to insert the items with C++

 Please help and Thanks

Posts: 188
Registered: ‎07-19-2012
My Device: Z10 LE
My Carrier: Three

Re: ListView of CheckBoxes with C++

An ArrayDataModel only has one level of items. If you wanted both a Header and a ListItem in your list, you'd need to use a GroupDataModel instead. Alternatively, you could put this Javascript function into your ArrayDataModel to force the item type to always be "listItem"


function itemType(indexPath) {
    return "listItem";


Did this post help you? If so, please make sure to "like" it!