1 Reply Latest reply on May 1, 2007 7:36 AM by peterent

    Copying Datagrid row problem

    ChickenSupreme
      Hi,

      im trying to copy a datagrid row and add it to the datagrid using the following code:

      userList.addItem(userList.getItemAt(myDataGrid.selectedIndex));


      where:
      myDataGrid is a datagrid and userList is an ArrayCollection which is the datagrids dataprovider.

      What i notice is that after copying, the first row is no longer clickable, and i notice in the debugger that the new row has the same reference value as the first row. How does one get around this? Do i need to recreated the content of the row into a new object before adding it to userList?

      Thanks in advance
      Eric
        • 1. Re: Copying Datagrid row problem
          peterent Level 2
          If you want to copy a record from a DataGrid's dataProvider you do it like this:

          var item:Object = userList.getItemAt( myDataGrid.selectedIndex );

          item is now a reference to the object at the specified location. It is *not* a copy. You have to manually copy the object. There is an object copy function in mx.utils.ObjectUtil which can help.

          var copy:Object = mx.utils.ObjectUtil( item );

          now add that item to the dataProvider:

          userList.addItem( copy );