4 Replies Latest reply on May 10, 2010 10:08 AM by gtbus

    DataGrid setting its selectedItem property to null after sort


      I load my application and initially the first item on the grid is selected.


      After I sort the one column on the grid, it sets it's selectedItem to null.  I cannot figure out where this call is coming from.


      I use an ArrayCollection as the grid's dataProvider, and on each click or refresh of the grid (eg. a sort) I make a call to the db to refresh the selected record (selectedItem) on the grid.


      Using the flashdevelop debugger stack I can see that the selectedItem = null is fired when I assign the record coming back into the place where it belongs in the ArrayCollection (using its index).  The strange thing is, this selectedItem = null fires out because the ArrayCollection appears to no longer have this record in it.  Checking the ArrayCollection's length (in the debugger stack) I can see it's 1 item short of its source's length (eg ArrayCollection.length is 6 when ArrayCollection.source.length is 7).


      This is very strange !!!


      Any suggestions appreciated !!!




      By the way, I can code around this, by setting the ArrayCollection's source as the record coming back from the db rather than the ArrayCollection itself, or by making a for loop through the AC and only assign the record coming back if it finds it, both ways the application works as desired, but I don't want to put this in without knowing why this problem occurs. thanks.