Alternating item colors in ComboBox dropdown

by Peter deHaan on December 19, 2007

in ComboBox

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"]);

{ 1 comment… read it below or add one }

1 jay May 7, 2009 at 6:01 am

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

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: