1 Reply Latest reply on Oct 13, 2009 3:15 AM by Subeesh Arakkan

    How do I remove a selected item from a datagrid?

    xandesign Level 1

      Hi all,

       

      I have a datagrid in my flex project which has a checkbox on each row which allows the user to select a row for deletion. I have a actionscript function which loops through all items looking for a selected item to remove but I don't know how to remove the selected item from the datagrid once found.

       

      Can someone tell me how I can remove selected items from my datagrid?

       

      I've included the code from my function below, any help would be much appreciated.

       

      Thanks in advance,

       

      Xander

       

       

      /**

      * Delete button click event.

      */

      private function deleteClick():void {

      var selectedItems:ArrayCollection = sectionDatagrid.dataProvider as ArrayCollection;

      var deleteArray:Array = new Array();

      var index:int = 0;

       

       

      for each (var item:Object in selectedItems) {

      if (item.selected == true) {

      deleteArray[index] = "DELETE FROM core_resources WHERE iid=" + item.iid + ";";

      index++;

       

       

      //insert code here to remove selected item

      }

      }

      }

        • 1. Re: How do I remove a selected item from a datagrid?
          Subeesh Arakkan Level 4

          private function deleteClick():void {

          var selectedItems:ArrayCollection = sectionDatagrid.dataProvider as ArrayCollection;

          var deleteArray:Array = new Array();

          var dp:ArrayCollection= new ArrayCollection();

           

           

          for each (var item:Object in selectedItems) {

          if (item.selected == true)

               deleteArray.push(item);

          else

               dp.addItem(item);

           

          }

          sectionDatagrid.dataProvider = dp;

          }