Adobe Flex: Set Selected Item In ComboBox

Oddly, Flex does not let you set an item to be selected in its ComboBox component. While the selectedIndex property can be used, you would have to make your own method to loop through the ComboBox’s dataProvider contents to get the index. Luckily, someone saved us the trouble of creating our own component extending ComboBox. Use the code below to be used as a substitute component for mx:ComboBox.

To use this custom made ComboBox, if your component file is under the folder com/ui/ then you have to specify it in the xml namespace. Setting the item in the ComboBox to be selected can be done by calling the selectedValue property (see code below).

Related Posts Plugin for WordPress, Blogger...

tags: ,

  1. 16 Responses to “Adobe Flex: Set Selected Item In ComboBox”

  2. …doesn’t work for me. Error when compiling.

    By andrew on Dec 24, 2008

  3. er, what does the error say? the code above does not compile correctly. you need to supply the correct data provider info (that will be used to retrieve data from the database) and the string_value should be replaced as well.

    By tech on Dec 26, 2008

  4. doesn’t work for me either.

    i’m confused with the “STRING_VALUE”

    if fill the dataProvider is card.
    with the definition:

    public var cards:ArrayCollection = new ArrayCollection(
    [ {label:”Visa”, data:1},
    {label:”MasterCard”, data:2},
    {label:”American Express”, data:3} ]);

    how can i choose “MasterCard”?
    i fill selectedValue=”MasterCard”, but nothing happen

    By Abs on Apr 14, 2009

  5. hi, sorry i have not tried using ArrayCollection

    By tech on Apr 14, 2009

  6. Hi, this code work? Can you send a example to my mail?
    Thanks a lot !!

    By Willinos on Sep 19, 2009

  7. yes, this code works :)

    By tech on Sep 19, 2009

  8. Hey! ……… i’m getting a
    ‘Error: Classes must not be nested.’ when trying to implement this……any ideas?

    By Kyle Ward on Oct 14, 2009

  9. hey, sorry man. i have not touched flex ever since i posted the code. can’t help you. maybe someone else can give you a hint

    By tech on Oct 14, 2009

  10. Hope you are doing great… I have project in (web development) Flex ColdFusion and SQL. I need someone to work on that project from beginning to end. I want a person who I can email if there is a problem and the problem is fixed in 24 hour period. The project hasn’t started yet.
    But if you are interested then please let me know your hourly rate. I like the idea of invoice and will pay based on the same…
    This is for the person who can give attention to my project if not daily at least every other day…. So please think and let me know if interested…

    By seema on May 4, 2010

  11. sorry. dont know coldfusion so i cant help

    By tech on May 4, 2010

  12. Hi,

    I did it this way :

    combobox.prompt=”Value”;
    combobox.selectedIndex = -1;

    By TA on May 7, 2010

  13. refer
    http://www.forta.com/blog/index.cfm/2006/11/22/Flex-ComboBox-With-selectedValue-Support

    for updated combo component..

    By RavikumarGM on Jun 4, 2010

  14. hey thanks for this man

    By tech on Jun 4, 2010

  15. thank you so much.It helped me a lot.

    By sreeja on Dec 5, 2010

  16. you are welcome

    By tech on Dec 5, 2010

  1. 1 Trackback(s)

  2. Mar 19, 2009: Websites tagged "boolean" on Postsaver

Post a Comment