You are doing a few things wrong here. use the following source in
your itemrenderer.mxml file

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
xmlns:local="*" >

<mx:Script>
<![CDATA[
        import mx.events.ListEvent;

[Bindable] private var dp:Array = [
        { symbol: "ADBE", name: "Adobe Systems Inc.", price: 49.95, bold: true 
},
        { symbol: "MACR", name: "Macromedia Inc.", price: 39.95, bold: false },
        { symbol: "MSFT", name: "Microsoft Corp.", price: 25.95, bold: true },
        { symbol: "IBM", name: "IBM Corp.", price: 42.55, bold: false }
        ];

private function changeHandler(event:ListEvent):void
{
        var item: Object = event.itemRenderer.data;
        
        item.bold = !item.bold;
        dg1.dataProvider.itemUpdated(item);
}

// Sets the styles to display the DataGrid Items 
private function computeStyles(data:Object, column:DataGridColumn):Object
{
        var o:Object = new Object();

        var bold:String = data["bold"]; 
        if (bold == "true")
        {
                o.bold = true;
        } else {
                o.bold = false;
        }
        
        return o;       
}


]]>
</mx:Script>

<mx:DataGrid id="dg1" dataProvider="{dp}" 
        change="changeHandler(event)" paddingTop="0" paddingBottom="0"
verticalAlign="middle" >
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="name" width="140"/>
<mx:DataGridColumn headerText="Symbol" dataField="symbol" width="60" />
<local:CustomColumn stylesFunction="computeStyles" headerText="Price"
dataField="price" itemRenderer="CustomRenderer" />
</mx:columns> 
</mx:DataGrid>

</mx:Application>

The most important issue here is that the changeHandler is modifying
the dp array which is not the same as the dataprovider of the grid.
you need to get a handle to the actual item in the grid's dataprovider
using the event.itemrenderer.data property and make changes to it. I

HTH

- venkat
http://www.venkatj.com

--- In [email protected], "m.frigge" <[EMAIL PROTECTED]> wrote:
>
> Hey Mark,
> 
> I'm struggling with itemRenderers too. First of all here
>
<http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.h\
> tml>  is a link to Alex's blog speaking about itemRenderers and showing
> some nice examples. In the BlinkWhenDataChanged example he is changing
> Background settings. I tried to adopt his itemRenderer and change it so
> that it checks a data value and sets the textFormat depending on what
> value the data has. This
> <http://16-bits.com/ItemRenderer/ItemRenderer.html>  is how far i came.
> I toggle the value on change, so when you click it the style changes. My
> only Problem is that it doesn't work anymore after sorting the dataGrid
> by one of its columns. Maybe we can work on this together :-).
> 
> Cheers, Max
> 
> --- In [email protected], "oneproofdk" <mark@> wrote:
> >
> > Hi.
> > In a itemrenderer I'd like to access a {data} value in a Script in the
> > itemrenderer. I just can't figure out how to do this.
> >
> > I have an ArrayCollection as the dataprovider for the DataGrid.
> > In a Column, I sue a itemrenderer "status"
> >
> > Inside renderer.status.as I have a VBox, with a init() function.
> > Inside init I'd like to test if "data.repeating" != null and if so,
> > set a label to a specific value, if not null, set to another value.
> >
> > <vbox><script></script><label/></vbox>
> >
> > Please - can anyone help me out with an example on how to accomplish
> > this, I hope, simple task.
> >
> > (The reason for using a VBox was that I had my hopes for setting the
> > background color also, so if != null color=XX + text = XX etc.
> >
> > Thanks for your time
> > Mark
> >
>


Reply via email to