I appreciate the response, but that is not the problem.  The code is 
adding the items to an ArrayCollection, not the datagrid directly.  
It is up to the datagrid (once instantiated) to retrieve the data 
from the arraycollection which was set as a data provider.

The problem was (as I mentioned in the previous post) that the 
datagrid fires off multiple itemEditEnd events.  This is because, 
when you hit Return or Tab on the edited field, the datagrid will 
send the itemEditEnd event for the current field, THEN it will 
automatically go to the next column (if Tab pressed) or next row (if 
Return pressed).  This would normally open another itemEditor for the 
next cell.  However, since I was creating a Popup from within the 
first itemEditEnd event, the next itemEditor will lose focus 
immediately.  Then the datagrid will fire off ANOTHER itemEditEnd for 
that next item (with reason == OTHER).

I finally saw this behavior when tracing all the details of the 
DataGridEvent.  The related issue of PopupManager (and I guess 
SystemManager) not being able to work on creating two new popup 
windows at the same time is still there.  You can just work around it 
by capturing the datagrid events and using event.preventDefault() and 
datagrid.destoryItemEditor() to keep another cell from starting to be 
edited.

Essentially, my solution was:

private function onItemEditEnd(event:DataGridEvent):void {

if(event.reason == DataGridEventReason.CANCELLED ||
   event.reason == DataGridEventReason.OTHER)
return;

// get the edited data
mydata = myDatagridObject.itemEditorInstance.data as [mydata's type];

event.preventDefault();   // stop next row/column from being edited
myDatagridObject.destoryItemEditor();   // get rid of item editor

createPopupWindow(mydata);
}


--- In [email protected], "Igor Costa" <[EMAIL PROTECTED]> wrote:
>
> The problem in your code friend is because you´re trying to add 
itens to an
> datagrid without existing first.
> 
> you can only add that if you have already created the container for 
it. so
> addChild or initiate the popup before you do that.
> 
> 
> and will works.
> 
> regards
> Igor Costa
> www.igorcosta.org
> www.igorcosta.com
> 
> On Dec 12, 2007 1:49 AM, wpbarto <[EMAIL PROTECTED]> wrote:
> 
> >   Additional Info: This problem is apparantly caused by MULTIPLE
> > itemEditEnd events dispatched from the DataGrid, exacerbated by 
the
> > fact that the PopupManager code is not "reentrant" or doesn't
> > handle "concurrency". Looks like Flash player can interrupt part 
of
> > a running script (PopupManager's addPopup thread) and begin
> > additional events.
> >
> > So:
> > 1. Why is dataGrid sending 4-5 (!) itemEditEnd events for one edit
> > action?
> > 2. Shouldn't PopupManager be reliable and opaque without 
developers
> > having to code around it's quirks?
> >
> > (Don't get me wrong--I love Flex; just don't like banging my head
> > over framework issues. I have enough banging for my own issues!)
> >
> > --- In [email protected] <flexcoders%40yahoogroups.com>,
> > "wpbarto" <william.barto@>
> >
> > wrote:
> > >
> > > I saw something else similar in flexcoders, but the information
> > > didn't seem to apply to this case. I can create a popup window
> > from
> > > a button's click handler, but THE SAME CODE used when editing a
> > > DataGrid cell FAILS!
> > >
> > > Is it a bug or a mis-use of PopupManager?? Thanks for any help!
> > >
> > > Top part of Error stack:
> > > RangeError: Error #2006: The supplied index is out of bounds.
> > > at flash.display::DisplayObjectContainer/addChildAt()
> > > at
> > >
> > 
mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal:
> > > :rawChildren_addChildAt()
> > > at mx.managers::SystemManager/addChild()
> > > at mx.managers::PopUpManagerImpl/addPopUp()
> > > at mx.managers::PopUpManager$/addPopUp()
> > > at TestPopup/::onCellEdit()
> > > at TestPopup/__pointGrid_itemEditEnd()
> > > at
> > >
> > 
flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEv
> > > entFunction()
> > > at flash.events::EventDispatcher/dispatchEvent()
> > > at mx.core::UIComponent/dispatchEvent()
> > > at mx.controls::DataGrid/::endEdit()
> > > at mx.controls::DataGrid/::deactivateHandler()
> > > at
> > >
> > 
flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEv
> > > entFunction()
> > > at flash.events::EventDispatcher/dispatchEvent()
> > > at mx.core::UIComponent/dispatchEvent()
> > > at mx.controls::DataGrid/::endEdit()
> > >
> > > This is the smallest example I can create:
> > >
> > > [File1: TestPopup.mxml]
> > > 
==================================================================
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> > > layout="absolute" applicationComplete="onAppComplete()">
> > > <mx:Script>
> > > <![CDATA[
> > > import mx.managers.PopUpManager;
> > > import mx.collections.ArrayCollection;
> > > import mx.events.DataGridEvent;
> > > import mx.events.DataGridEventReason;
> > >
> > > private var popWin:MyPopupWindow = null;
> > >
> > > private var curData:ArrayCollection; // items for datagrid
> > >
> > > private var items:ArrayCollection; // items for pop up
> > >
> > > private function onAppComplete():void {
> > > curData = new ArrayCollection();
> > > curData.addItem( { ident:"ORD", cityname:"Chicago, IL" } );
> > > curData.addItem( { ident:"ATL", cityname:"Atlanta, GA" } );
> > > curData.addItem( { ident:"DEN", cityname:"Denver, CO" } );
> > > curData.addItem( { ident:"", cityname:"" } ); // one blank
> > >
> > > pointGrid.rowCount = 5;
> > > pointGrid.dataProvider = curData;
> > >
> > > items = new ArrayCollection();
> > > items.addItem( {ident:"JFK", cityname:"New York, NY"} );
> > > items.addItem( {ident:"LAX", cityname:"Los Angeles, CA"} );
> > > items.addItem( {ident:"SEA", cityname:"Seattle, WA"} );
> > > }
> > >
> > > private function onClick():void {
> > > if(popWin == null) {
> > > popWin = new MyPopupWindow();
> > > popWin.itemChoices = items;
> > > }
> > > PopUpManager.addPopUp(popWin, this, true);
> > > PopUpManager.centerPopUp(popWin);
> > > }
> > >
> > > private function onCellEdit(event:DataGridEvent):void {
> > > if(event.reason == DataGridEventReason.CANCELLED)
> > > return;
> > > if(popWin == null) {
> > > popWin = new MyPopupWindow();
> > > popWin.itemChoices = items;
> > > }
> > > PopUpManager.addPopUp(popWin, this, true);
> > > PopUpManager.centerPopUp(popWin);
> > > }
> > > ]]>
> > > </mx:Script>
> > >
> > > <mx:VBox>
> > > <mx:Label text="Clicking the button creates popup OK:" />
> > > <mx:Button id="theButton" label="Click Me" click="onClick()"/>
> > > <mx:Label text="However, editing a cell FIRST fails:" />
> > > <mx:DataGrid id="pointGrid" itemEditEnd="onCellEdit(event)"
> > > editable="true">
> > > <mx:columns>
> > > <mx:DataGridColumn id="identCol" width="50" dataField="ident"
> > > headerText="Ident"/>
> > > <mx:DataGridColumn id="citynameCol" width="90"
> > > dataField="cityname" headerText="City/Name" paddingLeft="1"
> > > paddingRight="1"/>
> > > </mx:columns>
> > > </mx:DataGrid>
> > > </mx:VBox>
> > > </mx:Application>
> > >
> > > [File2: MyPopupWindow.mxml]
> > > 
==================================================================
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml";
> > layout="absolute"
> > > width="400" height="300" title="The Popup Window">
> > >
> > > <mx:DataGrid id="selItemList" dataProvider="{itemChoices}"
> > > width="100%" height="100%">
> > > <mx:columns>
> > > <mx:DataGridColumn id="identCol" dataField="ident"
> > > headerText="Ident"/>
> > > <mx:DataGridColumn id="typeCol" dataField="cityname"
> > > headerText="City"/>
> > > </mx:columns>
> > > </mx:DataGrid>
> > > <mx:ControlBar width="100%">
> > > <mx:Spacer width="100%"/>
> > > <mx:Button label="Cancel" click="onCancel()"/>
> > > </mx:ControlBar>
> > >
> > > <mx:Script>
> > > <![CDATA[
> > > import mx.managers.PopUpManager;
> > > import mx.collections.ArrayCollection;
> > >
> > > [Bindable] public var itemChoices:ArrayCollection =
> > > new ArrayCollection();
> > >
> > > private function onCancel():void {
> > > PopUpManager.removePopUp(this);
> > > }
> > > ]]>
> > > </mx:Script>
> > > </mx:Panel>
> > >
> >
> >  
> >
> 
> 
> 
> -- 
> ----------------------------
> Igor Costa
> www.igorcosta.com
> www.igorcosta.org
>


Reply via email to