The following example shows how you can set alternating item/row colors in a ComboBox control’s dropdown menu by setting the alternatingItemColors style using MXML, ActionScript or CSS

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/12/19/alternating-item-colors-in-combobox-dropdown/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">

    <mx:ComboBox id="comboBox"
            alternatingItemColors="['red', 0x00FF00, '#0000FF']">
        <mx:dataProvider>
            <mx:Array>
                <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:Array>
        </mx:dataProvider>
    </mx:ComboBox>

</mx:Application>

View source is enabled in the following example.

You can also set the alternatingItemColors style in an external style sheet or <mx:Style /> block, using the following snippet:

ComboBox {
    alternatingItemColors: #FF0000, #00FF00, #0000FF;
}

Or you can set the alternatingItemColors style using ActionScript, as seen in the following snippet:

comboBox.setStyle("alternatingItemColors", ["red", 0x00FF00, "#0000FF"]);
 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

0 Responses to Alternating item colors in ComboBox dropdown

  1. jay says:

    Thats a good one… is there a way to get the

Leave a Reply

Your email address will not be published.

You may 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