Avg. Rating 2.0

Problem

You want to set the number of items that appear at once in a Flex ComboBox control's dropdown menu.

Solution

The following example shows how you can set the number of visible items in a Flex ComboBox control’s dropdown menu by setting the rowCount property.

Detailed explanation

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/11/setting-the-number-of-visible-items-in-a-combobox-controls-dropdown-menu-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">

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

            private function numericStepper_change(evt:NumericStepperEvent):void {
                callLater(comboBoxOpen);
            }

            private function comboBoxOpen():void {
                comboBox.open();
            }
        ]]>
    </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:Object label="Seven" />
        <mx:Object label="Eight" />
        <mx:Object label="Nine" />
    </mx:Array>

    <mx:ApplicationControlBar dock="true">
        <mx:NumericStepper id="numericStepper"
                minimum="0"
                maximum="10"
                change="numericStepper_change(event);" />
    </mx:ApplicationControlBar>

    <mx:ComboBox id="comboBox"
            dataProvider="{arr}"
            rowCount="{numericStepper.value}"
            openDuration="0"
            closeDuration="0"
            width="100" />

</mx:Application>

For more information, see "Setting the number of visible items in a ComboBox control's dropdown menu in Flex" at FlexExamples.com.

Report abuse

Related recipes