2 Replies Latest reply on May 4, 2010 10:22 PM by cdub

    Selected index when sorting?

    cdub

      I have an app that makes modifications to an item in an array collection based on that item being selected in a datagrid. What I mean is that you select the row that you want to modify in the datagrid and then click a button to modify it. I was using the selected index to determine which index to add the mofified item. Here's where I determine which item in the array gets replaced:

       

                      var theIndex:Number = theGrid.selectedIndex;
                      theCollection.removeItemAt( theIndex );
                      theCollection.addItemAt( { stuff: theStuff }, theIndex );

       

      Which works great... until you sort the datagrid. Obviously this doesn't work when once sorted, since the indexes are no longer in sync but what do I need to do in order to fix this? Is there a way to determine what the what the index in the array is when you select the row in a datagrid?

        • 1. Re: Selected index when sorting?
          Vikash.kumar29

          Hi,

           

          There are two ways through which you can accomplish this task.

           

          1.             var theIndex:Number = theGrid.selectedIndex;

                          (theGrid.dataProvider as ArrayCollection).removeItemAt( theIndex );

                          (theGrid.dataProvider as ArrayCollection).addItemAt( { stuff: theStuff }, theIndex );

           

           

          Another solution :

          2.             var theIndex:Number = theCollection.getItemIndex(theGrid.selectedItem);
                          theCollection.removeItemAt( theIndex );
                          theCollection.addItemAt( { stuff: theStuff }, theIndex );

           

           

           

          Hope this helps you.

          If this doesn't solves your problem, then please let me know

           

          Cheers

          -Vikash

          • 2. Re: Selected index when sorting?
            cdub Level 1

            Thanks!