2

I have a listview with checkbox. I want to get the values of selected items in the list view. How can i achieve the above..?

I have posted the screenshots below :

Screen shot

This is what i have tried :

// List view declaration and its elements :

ListView {
                verticalAlignment: VerticalAlignment.Center
                horizontalAlignment: HorizontalAlignment.Center
                layout: FlowListLayout {
                }
                dataModel: grouplistdatamodel
                listItemComponents: [

                    ListItemComponent {
                        type: "item"
                        Container {
                            Container {
                                layout: StackLayout {
                                    orientation: LayoutOrientation.TopToBottom
                                }
                                verticalAlignment: VerticalAlignment.Center
                                horizontalAlignment: HorizontalAlignment.Center
                                preferredWidth: 768
                                Container {
                                    verticalAlignment: VerticalAlignment.Center
                                    layout: StackLayout {
                                        orientation: LayoutOrientation.LeftToRight
                                    }
                                    CheckBox {
                                        verticalAlignment: VerticalAlignment.Center
                                    id:checkboxvalues
                                  text: ListItemData.firstname
                                   onCheckedChanged: {

                                   }


                                    }

                                }
                            }
                            Divider {
                                horizontalAlignment: HorizontalAlignment.Fill
                            }
                        }
                    }
                ]
                onTriggered: {
                _test.showToast(userid);
                }
                onCreationCompleted: {
                    group_DataSource.load();
                }
            }

Please help me to sort this out. Thanks in advance..!

Vendetta
  • 513
  • 2
  • 16
  • I think you can get it from the datamodel itself; the idea, when user check the checkbox, you also update the data model value (ie. the item data model should have variable state of checkbox); so in the end, you can always get the checkbox value&state from the data model that represent it – hakim Dec 28 '12 at 07:50
  • 1
    can you able to send some samples to do this – Vendetta Jan 07 '13 at 06:23

1 Answers1

3

I'm not sure about what you want to do exactly but here is how how I would store all the data checked by the user.

On onCheckedChanged :

ListView {
    ...
    listItemComponents: [
        ...
        onCheckedChanged: {
            ListItem.view.checkedDataChanged(ListItemData.firstname, checked);
        }
        ...
    ]
    function checkedDataChanged(data, isChecked) {
        controller.checkedDataChanged(data, isChecked);
    }
}
...

Where checkedDataChanged is a Q_INVOKABLE defined in the list controller's C++ class.

Then you can manage your data selected easily in a QList for instance.

Hope this helps !

CAMOBAP
  • 5,523
  • 8
  • 58
  • 93
nicolas
  • 234
  • 4
  • 11