Let me see if I understand this. You are saying that if you are 
editing selectedIndex 3, and then you click, for example, on index 4, 
that you are getting index 5 instead of 4, correct?

Do you get the data from index 4 or 5? When you update data in the 
DG, don't you need to refresh the DG?

--- In [email protected], "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> My flag solution works fine, so don't stress on this one unless you 
are
> just interested.
> 
> Tracy
> 
>  
> 
> ________________________________
> 
> From: [email protected] 
[mailto:[EMAIL PROTECTED] On
> Behalf Of Tracy Spratt
> Sent: Tuesday, May 06, 2008 7:31 PM
> To: [email protected]
> Subject: [flexcoders] Complex itemEditEnd processing confuses 
subsequent
> rowIndex on click
> 
>  
> 
> In a component's editable Datagrid's itemEditEnd handler, I update a
> data model instance, which dispatches events that invoke a 
ChangeWatcher
> handler back in that same component.  That handler assigns a new
> XMLListCollection to the local var to which the editable dataGrid is
> bound.  The handler also sets the selectedIndex of the DG to the 
just
> edited row.
> 
> This all works fine if I end the editing session using Tab or Enter 
or
> Escape, but if I click in the next row, something confuses the 
rowIndex
> of the click, and the next row's cell is put in edit mode instead 
of the
> one clicked.
> 
> So far I have been unable to repro this in a test app (quit because 
of
> time issues), but it occurs both places that I use this methodology.
> 
> I also have found that there is some kind of event "tangle". When my
> change handler is invoked and re-assigns the DG dataProvider, we are
> still "within" the itemEditEnd handler, but assigning the DP causes 
us
> to hit the itemEditend handler AGAIN, recursively.
> 
> I am about ready to just set a flag and conditionally skip the 
problem
> code, but any other ideas will be appreciated.  I'll post some 
snippets
> below.
> 
> Tracy
> 
> Tracing:
> 
> onEditEnd()             //value updated, click in 2nd row(index
> 1),itemEditEnd handler called
> 
> ..onEditEnd rowIndex=0  //
> 
> changeProjItemData()    //updates the data model
> 
> onXmlProjItemsChange:   //ChangeWatcher handler
> 
> ..<-- here we assign the dg dataProvider -->
> 
> onEditEnd()             //UNEXPECTED call to itemEditEnd handler
> 
> ..onEditEnd rowIndex=0
> 
> selectItemByIndex( 0)
> 
> onSelectItem            //called by DG change event handler, 2nd
> row(index 1) clicked
> 
> ..set _iSelectedIndex to row clicked=2  //WRONG index, clicked 
index "1"
> 
> ..<-- here , the 3rd row is set to editable, not the 2nd as clicked
> 
> Snippets:
> 
>   /**This gets fired when the itemEditor is about to be destroyed. 
*/
> 
>   private function onEditEnd(event:DataGridEvent):void
> 
>   {
> 
>     trace(".ProjItem.onEditEnd()")
> 
>     var sPropertyName:String = event.dataField;         //get the
> dataField
> 
>     var sValue:String =
> TextInput(event.currentTarget.itemEditorInstance).text; //and value
> 
>     trace(".....onEditEnd rowIndex=" + event.rowIndex ) 
> 
>     if (_xmlProjItem[sPropertyName] != sValue) {        //if value
> changed
> 
>       changeProjItemData(sPropertyName,sValue)
> 
>       event.preventDefault();
> 
>     }
> 
>   }//onEditEnd
> 
>   
> 
>   /** Sets required save flags, updates the local value, and 
updates the
> data model */ 
> 
>   private function changeProjItemData(sPropertyName:String,
> sValue:String):void
> 
>   {
> 
>     trace(".ProjItem.changeProjItemData()")
> 
>     if (sPropertyName && sValue) {
> 
>       [EMAIL PROTECTED] = "true";                  //flas 
for
> save
> 
>       _xmlProjItem[sPropertyName] = sValue;
> 
>       [EMAIL PROTECTED] = "true";
> 
>       [EMAIL PROTECTED] 
= "true";          //required
> for SAVE!
> 
>       [EMAIL PROTECTED] = "true";              // "
> 
>       [EMAIL PROTECTED] = "true";
> 
>       _dsApp.xmlProjItems = 
_xmlProjItems;                  //Update the
> data model.  Invokes change handler
> 
>     }
> 
>   }//changeProjItemData  
> 
>   /** changeWatcher handler on DSApp.xmlProjItems */
> 
>   private function onXmlProjItemsChange( event:PropertyChangeEvent
> ):void
> 
>   {
> 
>     trace("...Project.onXmlProjItemsChange:")
> 
>     var xml:XML = event.newValue as XML;
> 
>     if (xml) {
> 
>       _xmlProjItems = xml.copy();
> 
>       _xlcProjItems = new
> XMLListCollection(_xmlProjItems.children().(attribute("rowaction")!
="del
> ete")); //dgProjItem dataProvider
> 
>       selectItemByIndex(_iSelectedIndex);
> 
>     }
> 
>     else  {
> 
>       _xmlProjItems = <DocumentElement />;
> 
>       _xmlProjItem = null;
> 
>       _xlcProjItems = new XMLListCollection(_xmlProjItems.ProjItem);
> 
>     }
> 
>   }//onXmlProjItemsChange  
> 
>   
> 
>   /** Run by change event of dgProjItem */
> 
>   private function onSelectItem(event:Event):void
> 
>   {
> 
>     trace(".projItem.onSelectItem -- current _iSelectedIndex =  " +
> _iSelectedIndex)
> 
>     _xmlProjItem = XML(event.target.selectedItem);
> //set local var
> 
>     _iSelectedIndex = event.target.selectedIndex;
> //store index
> 
>     trace("....set _iSelectedIndex to row clicked=" + 
_iSelectedIndex);
> 
>     bPrevAvail = (_iSelectedIndex > 0);
> //next/prev button state
> 
>     bNextAvail = (_iSelectedIndex < _xmlProjItems.children().length
() -
> 1);
> 
>     _dsApp.xmlProjItem = _xmlProjItem;
> //set data model
> 
>   }//onSelectItem  
> 
>   
> 
>   /** Selects previously stored row */
> 
>   private function selectItemByIndex(iIndex:int):void
> 
>   {
> 
>     trace(".projItem.selectItemByIndex( " + iIndex + ")")
> 
>     _xmlProjItem = _xmlProjItems.ProjItem[iIndex];      //select the
> first Item
> 
>     dgProjItems.selectedIndex = iIndex;  
> 
>     _iSelectedIndex = iIndex;  
> 
>     bPrevAvail = (_iSelectedIndex > 0);
> 
>     bNextAvail = (_iSelectedIndex < _xmlProjItems.children().length
() -
> 1);    
> 
>     _dsApp.xmlProjItem = _xmlProjItem;
> 
>   }//selectItemByIndex
>


Reply via email to