Thanks Valdhor. Worked like a charm.


________________________________
From: valdhor <[email protected]>
To: [email protected]
Sent: Mon, 12 July, 2010 11:35:16
Subject: [flexcoders] Re: Setting Different Style on ComboBox DropdownList

  
Use an Item Renderer...

Test1.mxml:
<?xml version="1.0" encoding="utf- 8"?>
<mx:Application xmlns:mx="http: //www.adobe. com/2006/ mxml" layout="vertical">
    <mx:Script>
        <![CDATA[
            [Bindable] private var dp:Array = [
                {ColorName: "Red", ColorHex: "#FF0000"},
                {ColorName: "Blue", ColorHex: "#0000FF"},
                {ColorName: "Yellow", ColorHex: "#FFFF00"}
                ];
        ]]>
    </mx:Script>
    <mx:ComboBox dataProvider= "{dp}" labelField=" ColorName" itemRenderer= 
"Test1ItemRender er"/>
</mx:Application>


Test1ItemRenderer. as:
package
{
    import mx.controls. *; 
    
    public class Test1ItemRenderer extends Text
    {
        private var colorHex:String;
        
        public function Test1ItemRenderer( )
        {
            super();
        }

        override public function set data(value:Object) :void
        {
            if(value != null)
            {
                super.data = value;
                colorHex = value.ColorHex;
            }
        }
        
        override protected function updateDisplayList( unscaledWidth: Number, 
unscaledHeight: Number):void 

        { 
            super.updateDisplay List(unscaledWid th, unscaledHeight) ; 
            setStyle("color" , colorHex);
        }
    }
}


--- In flexcod...@yahoogro ups.com, Angelo Anolin <angelo_anolin@ ...> wrote:
>
> Hi Flexcoders,
> 
> How would I be able to set different styles on the list of a combo box based 
> on 
>
> the values for the binding list to that?
> 
> For example, I have some data retrieved as follows:
> 
> ColorName  ColorHex
> Red        #FF0000
> Blue       #0000FF
> Yellow     #FFFF00
> 
> And I am binding it to the combo box.
> 
> Now When I show the list of the combo box, the LabelField maps to the 
> ColorName 
>
> column and I want to display the ColorName based on its color as defined in 
> the 
>
> ColorHex column.
> 
> Any tips?
> 
> Thanks.
>

 


      

Reply via email to