Creating multi-line list rows with variable row heights

by Peter deHaan on October 27, 2007

in HTTPService, List

The following example shows how you can create multi-line rows with wrapping text and variable row heights with the Flex List control.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/10/27/creating-multi-line-list-rows-with-variable-row-heights/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();">

    <mx:Script>
        <![CDATA[
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;

            private function init():void {
                commentsXML.send();
            }

            private function commentsXML_result(evt:ResultEvent):void {
                var resultXML:XML = evt.currentTarget.lastResult;
                list.dataProvider = resultXML.channel.item;
            }

            private function commentsXML_fault(evt:FaultEvent):void {
                mx.controls.Alert.show("Unable to load XML:\n" + commentsXML.url, "ERROR");
            }
        ]]>
    </mx:Script>

    <mx:HTTPService id="commentsXML"
            url="http://blog.flexexamples.com/comments/feed/"
            resultFormat="e4x"
            showBusyCursor="true"
            result="commentsXML_result(event);"
            fault="commentsXML_fault(event);" />

    <mx:List id="list"
            variableRowHeight="true"
            wordWrap="true"
            labelField="title"
            width="250" />

</mx:Application>

View source is enabled in the following example.

{ 4 comments… read them below or add one }

1 maliboo October 29, 2007 at 2:52 am

Is there any switch to freeze scroll thumb size?

Reply

2 peterd October 29, 2007 at 7:38 am

maliboo,

I don’t believe you can freeze the scroll thumb size. You can try filing an enhancement request in the public Flex bug system at http://bugs.adobe.com/flex/.

Peter

Reply

3 JabbyPanda November 12, 2009 at 2:19 am

If we will set on horizontalScrollPolicy=”on” then multi-line will not work, I guess it is a feature.

Reply

4 Peter deHaan November 12, 2009 at 7:12 am

@JabbyPanda,

Multi-line still works (at least it does in 3.4), it just wraps in a different spot. How/where were you expecting it to wrap if you set the horizontal scroll policy?

Peter

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: