0
votes

I have a Datagrid with an ArrayCollection as DataProvider, the arrayCollection is partially generated by a remoteObject call, the dataprovider seems to works at least until I try to edit the field...

By the RemoteObject I only receive an ArrayCollection with the field ip, but the datagrid looks for the fields ip, check and save... If I add/edit this new field it works, but only under particular condition

The DataGrid:

<s:DataGrid id="datagrid" left="10" right="10" top="136" 
            dataProvider="{listaIPCheck}" bottom="10" requestedRowCount="4">
    <s:columns>
        <s:ArrayList>
            <s:GridColumn dataField="ip" headerText="Asset"/>
            <s:GridColumn dataField="check" headerText="Inventory"/>
            <s:GridColumn dataField="save" headerText="Salvataggio"/>
        </s:ArrayList>
    </s:columns>
</s:DataGrid>

The Script:

[Bindable]private var listaIPCheck:ArrayCollection; 

private function ro_resultHandler(event:Event=null):void
{
  listaIPCheck = new ArrayCollection();
  listaIPCheck = ro.getListUpdate.lastResult;
  heap = 0;         
  // Read Below {POINT #1}
  init3();  
}

private function init3():void
{
 // Read Below {POINT #2}
 if (heap<listaIPCheck.length)
 {
    // omitted the initialization of the process p
    p.addEventListener(NativeProcessExitEvent.EXIT, onExit);
    try{                        
      p.start(startupInfo);
    }catch(e:Error){}
 }
}


private function onExit(e:NativeProcessExitEvent):void {    
    // Read below {POINT #3}
}

Here is my code, now as you can see there are 3 line where I wrote to read below... Let's assume to put this simple for instead of the commented line (once at a time)

for (var k:Number=0;k<listaIPCheck.length;k++)
{
  listaIPCheck.getItemAt(k).check = "checkVal";
  listaIPCheck.getItemAt(k).save = "saveVal";
}

This code always work in the 3 points, so at the end of the call the ArrayCollection is always filled with the new values, but the datagrid refresh the items only in point #1 and #2 Why not in Point #3???

1
Why did you omit the initilzation process for p? What is it? Since the DataGrid isn't editable, how are you editing the field? And what field are you editing? When you say the code doesn't work; what is the issue? How doesn't it work? Do you get a runtime error? Or do you see unexpected behavior?JeffryHouser
I omit the initialization process for P because is not relevant to the problem... using the for alternativly in the POINT 1-2-3 works and correctly update/add the value specified, the problem is that if I put the for in POINT 3 the ArrayCollection is edited but the change are not refreshed in the datagrid whereas in the point 1-2 is both updated (arrayCollection) and refreshed (by datagrid)Marcx

1 Answers

0
votes

The reason the DataGrid doesn't refresh when you change properties on an item in an ArrayCollection is that because changing the properties does not trigger the collectionChange event. The DataGrid has no way to know that properties within the object changed. It has to do with pointers and memory spaces and what exactly the DataGrid is looking at for binding purposes.

In most cases, the invalidateList() method to force a refresh of the display. You can call the refresh() method or the itemUpdated() method on the collection or replace the dataProvider completely to force a refresh.