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
Posts: 79
Registered: ‎02-04-2013
My Device: Z10 LE
Accepted Solution

dropdown options

Hi,

 

I need some help with options in dropdown menu.

How can I do something like  that:    if(something) ->  show some options in dropdown menu.   if(something else) -> show some other options. 

Developer
Posts: 229
Registered: ‎01-12-2013
My Device: z30

Re: dropdown options

I'm not sure if it's possible in QML but in C++ I guess it would be something like the next piece of code

 

DropDown *myDropDown = root->findChild<DropDown*>("objectNameOfMyDropDown");

if(something) {
	myDropDown->add(Option::create().text("Option 1"));
	myDropDown->add(Option::create().text("Option 2"));
	myDropDown->add(Option::create().text("Option 3"));
}
else {
	myDropDown->add(Option::create().text("Option 4"));
	myDropDown->add(Option::create().text("Option 5"));
	myDropDown->add(Option::create().text("Option 6"));
}

 If you want to change the content when a button is clicked, you can listen for that event and use the dropdown->removeAll() method to clear all the options. Then just repopulate the dropdown with dropdown->add(Option::create().text("Option"));

 

Hopefully this post helped you a little bit further.

______________________________________________________
BB10-OAuth: GitHub
Developer
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: dropdown options

Depending on what the if condition actually is you may be able to do it in Javascript, any more information?

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
Posts: 79
Registered: ‎02-04-2013
My Device: Z10 LE

Re: dropdown options

Actually I want options to be changed when other option in another dropdown is selected. 

 

Not much into c++ though.  Even after reading tutorials, I still don't get it, where this goes, main.cpp, app.cpp...?

DropDown *myDropDown = root->findChild<DropDown*>("objectNameOfMyDropDown");
Developer
Posts: 79
Registered: ‎02-04-2013
My Device: Z10 LE

Re: dropdown options

[ Edited ]

Kind of a: onSelectedIndexChanged: -> change options in other dropdown

Developer
Posts: 229
Registered: ‎01-12-2013
My Device: z30

Re: dropdown options

Maybe this topic can help you out

 

http://supportforums.blackberry.com/t5/Cascades-Development/Dynamically-populate-DropDown-with-Optio...

______________________________________________________
BB10-OAuth: GitHub
Developer
Posts: 79
Registered: ‎02-04-2013
My Device: Z10 LE

Re: dropdown options

Seems like the right thing, but still gotta learn how mix C++ and QML.
Developer
Posts: 229
Registered: ‎01-12-2013
My Device: z30

Re: dropdown options

I guess this link (https://developer.blackberry.com/cascades/documentation/dev/integrating_cpp_qml/index.html) can be a good start.

______________________________________________________
BB10-OAuth: GitHub
Developer
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: dropdown options

My solution (kind of hacky at the bottom though).

 

// Default empty project template
import bb.cascades 1.0

// creates one page with a label
Page {
    Container {
        layout: StackLayout {
        	orientation: LayoutOrientation.TopToBottom    
        }
        DropDown {
            id: wantCarDropDown
            title: "Do you want a car?"
            enabled: true

            onSelectedIndexChanged: {
                console.log("SelectedIndex was changed to " + selectedIndex);
                var vehicles = ['Boat', 'Cessna', 'Learjet', 'Hovercraft'];
                if(selectedValue === 'Yes')
                {
                    vehicles = ['Ferrari 458 Italia', 'Maserati Quattroporte', 'Audi R8'];
                }
                for (var i = 0; i < vehicles.length; i ++) {
                    var dynamicOption = newOption.createObject();
                    dynamicOption.text = vehicles[i];
                    dynamicOption.value = vehicles[i];
                    vehicleDropDown.add(dynamicOption);
                }
                vehicleDropDown.setEnabled(true);
            }
            Option {
                text: "Yes"
                value: "Yes"
            }
            Option {
                text: "No"
                value: "No"
            }
        }
        DropDown {
            id: vehicleDropDown
            title: "Choose a vehicle"
            enabled: false
        }
    }

    attachedObjects: [
        ComponentDefinition {
            id: newOption
            Option {
            }
        }
    ]
}

 

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
Posts: 79
Registered: ‎02-04-2013
My Device: Z10 LE

Re: dropdown options

Hmm,   I'm gonna give a try to this one QML only first, and I'll see where I get. Otherwise C++...:Sweatdrop: