Alternating row colors in a Flex List control

The following example shows how you can alternate row colors in a List control using the alternatingItemColors style.

Full code after the jump

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/17/alternating-row-colors-in-a-flex-list-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:ArrayCollection id="arrColl">
        <mx:source>
            <mx:Array>
                <mx:Object label="Row 1" />
                <mx:Object label="Row 2" />
                <mx:Object label="Row 3" />
                <mx:Object label="Row 4" />
                <mx:Object label="Row 5" />
                <mx:Object label="Row 6" />
                <mx:Object label="Row 7" />
                <mx:Object label="Row 8" />
            </mx:Array>
        </mx:source>
    </mx:ArrayCollection>

    <mx:List id="list"
            alternatingItemColors="[0xEEEEEE, 0xDFDFDF]"
            dataProvider="{arrColl}"
            rowCount="4"
            width="200" />

</mx:Application>

View source is enabled in the following example.

4 thoughts on “Alternating row colors in a Flex List control

  1. Hello, sory to comment on such an old post, but I just wanted to know if it possible to alternate the background alphas of the items in the list in a similar manner?

    Great Example, really saved a lot of time :)
    sharat87

  2. great example. I really find your blog useful for providing me help for my flex related development. Pleas keep the good work.

Comments are closed.