Hi Bruce,
I've been trying to figure this one out. As Tracy suggests, you could put something like this in the itemRenderer component? I'm not sure, however, how to associate the itemEditorInstance with the itemRenderer instance. This might get you a little closer.
-TH
<mx:Script>
<![CDATA[
import mx.core.Application;
import mx.events.DataGridEvent;
public function init():void // creationComplete of the itemRenderer
{
Application.application.myGrid.addEventListener(DataGridEvent.ITEM_EDIT_BEGIN, showResetState);
Application.application.myGrid.addEventListener(DataGridEvent.ITEM_EDIT_END, showDefaultState);
}
public function showResetState(event:DataGridEvent):void
{
// not sure exactly how, but you probably have to check here to see if the itemEditorInstance relates to this
// itemRenderer instance. Something like if (this = event.itemRenderer) {} ???
currentState = 'showReset';
}
public function showDefaultState(event:DataGridEvent):void
{
currentState = '';
}
]]>
</mx:Script>
--- In flexcoders@yahoogroups.com, "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> I think you need to do this via the underlying dataProvider, instead of
> trying to directly manipulate rendered controls.
>
>
>
> On the edit event of the text control, set a property in the
> corresponding dataProvider item. Have the item renderer respond to that
> value change by changing its state.
>
>
>
> Tracy
>
>
>
> ________________________________
>
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
> Behalf Of flex8it
> Sent: Monday, June 19, 2006 1:24 PM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Re: Getting a DataGrid item renderer instance
>
>
>
> More specifically, here's what I'm trying to change the viewState in
> my itemRenderer when the DataGrid's textfield is edited. But in
> order to do that, I need to somehow get an instance reference to my
> renderer component. And nothing I've done seems to work...
>
> <?xml version="1.0"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
> <http://www.adobe.com/2006/mxml> "
> xmlns:comp="components.*"
> verticalAlign="top" horizontalAlign="center"
> layout="absolute">
>
> <mx:Script>
> <![CDATA[
> import components.imgReset;
> import mx.collections.ArrayCollection;
> import mx.events.DataGridEvent;
> import mx.controls.Alert;
>
> [Bindable]
> public var choices:ArrayCollection = choices = new
> ArrayCollection([
> {resetImage: "images/reset.png", fieldName: "Smalltown"},
> {resetImage: "images/reset.png", fieldName: "Bigtown"},
> ]);
>
> private function changeRendererState(event:DataGridEvent) : void
> {
> // I can get the rowIndex and columnIndex for the renderer,
> // but I don't exactly how to use them to get to the
> renderer object...
> Alert.show(event.rowIndex + ", " + (event.columnIndex - 1));
>
> // I just want to get the renderer instance...
> // First, there's a problem with my typecasting ??
> // Second, there's no such thing as a row property on
> // the DataGrid, but I really want there to be...
> var RendererInstance:imgReset = imgReset(this.myGrid.columns
> [event.columnIndex-1].row[event.rowIndex].itemRenderer);
>
> // Now I want to manipulate renderer instance
> properties/states...
> RendererInstance.currentState = 'showReset';
> }
> ]]>
> </mx:Script>
> <mx:DataGrid id="myGrid"
> editable="true"
> dataProvider="{choices}"
> itemEditEnd="changeRendererState(event)" >
> <mx:columns>
> <mx:DataGridColumn dataField="resetImage"
> headerRenderer="components.HeaderReset"
> itemRenderer="components.imgReset"/>
> <mx:DataGridColumn dataField="fieldName"
> editable="true" width="230"
> headerText="Field Name" />
> </mx:columns>
> </mx:DataGrid>
> </mx:Application>
>
> I'd sure appreciate some help on this conundrum.
>
> Many Thanks,
> Bruce
>
> --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
> , "flex8it" bdenham@ wrote:
> >
> > I have simple datagrid with 2 columns and 2 rows like this:
> >
> > column 0 column 1
> > -------- ---------
> > image textfield
> > image textfield
> >
> > Column 0 contains my ImageRenderer component.
> > Column 1 contains the DataGrid's default item renderer and editor:
> > text, textfield.
> >
> > First Problem:
> > How do I identify/get a reference to a particular instance of my
> > ImageRenderer from, say, column[0], row[1]?
> >
> > Second (related) Problem:
> > How do I get the ImageRender instance that corresponds to the row
> of
> > the textfield that fires an event when edited?
> >
> > I've been wrestling with this problem for days now, and I just
> can't
> > seem to get a grasp on the communication/eventing infrastructure
> > that's probably necessary to pull this off. Please help.
> >
> > Thanks,
> > Bruce
> >
>
__._,_.___
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Web site design development | Computer software development | Software design and development |
Macromedia flex | Software development best practice |
YAHOO! GROUPS LINKS
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.