Preventing users from changing the ComboBox control in Flex

by Peter deHaan on July 10, 2008

in ComboBox

The following example shows how you can prevent users from changing the value in a Flex ComboBox control by setting the dropdown menu’s selectable property.

Full code after the jump.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/07/10/preventing-users-from-changing-the-combobox-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.events.DropdownEvent;

            private function comboBox_open(evt:DropdownEvent):void {
                comboBox.dropdown.selectable = checkBox.selected;
            }
        ]]>
    </mx:Script>

    <mx:Array id="arr">
        <mx:Object label="One" />
        <mx:Object label="Two" />
        <mx:Object label="Three" />
        <mx:Object label="Four" />
        <mx:Object label="Five" />
        <mx:Object label="Six" />
    </mx:Array>

    <mx:ApplicationControlBar dock="true">
        <mx:CheckBox id="checkBox"
                label="selectable:"
                labelPlacement="left"
                selected="false" />
    </mx:ApplicationControlBar>

    <mx:ComboBox id="comboBox"
            prompt="Please select an item"
            dataProvider="[One,Two,Three,Four,Five,Six]"
            open="comboBox_open(event);" />

</mx:Application>

{ 2 comments… read them below or add one }

1 Natasha August 29, 2008 at 3:52 am

Hi!
How can I prevent ComboBox from closing when clicking (selecting) its item. Thanks.

Reply

2 St.Woland October 22, 2009 at 8:52 am

Thank you so much! Just what I was looking for!

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: