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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 79
Registered: ‎02-04-2013
My Device: Z10 LE
My Carrier: Simobil
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: 230
Registered: ‎01-12-2013
My Device: z30
My Carrier: Mobile Vikings

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,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

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
My Carrier: Simobil

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
My Carrier: Simobil

Re: dropdown options

[ Edited ]

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

Developer
Posts: 230
Registered: ‎01-12-2013
My Device: z30
My Carrier: Mobile Vikings

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
My Carrier: Simobil

Re: dropdown options

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

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,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

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
My Carrier: Simobil

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++...