6 Replies Latest reply on Sep 17, 2007 8:16 AM by Bob Saggot

    deleting rows from grid --- need help

    lalson
      Hi All ,

      Need some help in deleting selected rows from grid. I am able to add rows to Grid. But unable to delete selected rows from Grid. Even user checks multiple rows its deleting only one row at a time. And one more problem I am facing is its not retaining the values entered by user if I add / delete rows to Grid.

      Here is the code what I tried for deleting and adding rows to Grid

      public function addOtherIncome():void
      {
      incomeData.addItem({Charterer:'',incomeDesc:'',incomeAmt:''});
      }



      public function deleteIncome():void
      {
      //Alert.show("Inside Delete Item" + checkIncome.length );
      for(var j:Number=0;j<checkIncome.length;j++)
      {
      Alert.show("inside of for "+ checkIncome[j].selected);
      if(checkIncome[j].selected==true)
      {
      incomeGridRow.height = 0;
      incomeData.removeItemAt(j);
      }
      }

      }


      incomeData ----- name of the data provider
      checkIncome ----- name of the checkbox
      incomeGridRow ----- name of the gridrow

      Anybody help me to solve these issues. I tried a lot to solve these issues. Thanx in advance

      Thanks & Regards,
      Lalitha
        • 1. Re: deleting rows from grid --- need help
          Level 7
          Just Try

          public function deleteIncome():void
          {
          if (incomeDate.lenght > 0)
          incomeData.removeItemAt(dataGridName.selectedIndex);
          }

          I hope this help.
          Rgds

          JFB



          "lalson" <webforumsuser@macromedia.com> wrote in message
          news:fc8mrn$f5g$1@forums.macromedia.com...
          > Hi All ,
          >
          > Need some help in deleting selected rows from grid. I am able to
          > add
          > rows to Grid. But unable to delete selected rows from Grid. Even user
          > checks
          > multiple rows its deleting only one row at a time. And one more problem I
          > am
          > facing is its not retaining the values entered by user if I add / delete
          > rows
          > to Grid.
          >
          > Here is the code what I tried for deleting and adding rows to Grid
          >
          > public function addOtherIncome():void
          > {
          > incomeData.addItem({Charterer:'',incomeDesc:'',incomeAmt:''});
          > }
          >
          >
          >
          > public function deleteIncome():void
          > {
          > //Alert.show("Inside Delete Item" + checkIncome.length );
          > for(var j:Number=0;j<checkIncome.length;j++)
          > {
          > Alert.show("inside of for "+ checkIncome[j].selected);
          > if(checkIncome[j].selected==true)
          > {
          > incomeGridRow.height = 0;
          > incomeData.removeItemAt(j);
          > }
          > }
          >
          > }
          >
          >
          > incomeData ----- name of the data provider
          > checkIncome ----- name of the checkbox
          > incomeGridRow ----- name of the gridrow
          >
          > Anybody help me to solve these issues. I tried a lot to solve these
          > issues. Thanx in advance
          >
          > Thanks & Regards,
          > Lalitha
          >


          • 2. Re: deleting rows from grid --- need help
            lalson Level 1
            Hi,

            Thanks for ur reply. I have a clarification here in the line " incomeData.removeItemAt(dataGridName.selectedIndex) " . I am using grid and not datagrid in my code. The selectedIndex property is not present for grid .Inside <mx:Grid> i am having a <mx:Repeater id="repIncome" dataProvider="incomeData"> and inside repeater i am having gridRow.Here incomeData is an ArrayCollection.

            Thanks & Regards,
            Lalitha
            • 3. Re: deleting rows from grid --- need help
              Level 7
              Ups.. sorry, never use grid
              Check this sample.
              http://www.cflex.net/showFileDetails.cfm?ObjectID=687

              Rgds
              JFB

              "lalson" <webforumsuser@macromedia.com> wrote in message
              news:fcaotp$r2p$1@forums.macromedia.com...
              > Hi,
              >
              > Thanks for ur reply. I have a clarification here in the line "
              > incomeData.removeItemAt(dataGridName.selectedIndex) " . I am using grid
              > and not
              > datagrid in my code. The selectedIndex property is not present for grid
              > .Inside <mx:Grid> i am having a <mx:Repeater id="repIncome"
              > dataProvider="incomeData"> and inside repeater i am having gridRow.Here
              > incomeData is an ArrayCollection.
              >
              > Thanks & Regards,
              > Lalitha
              >


              • 4. deleting rows from grid --- need help
                lalson Level 1
                Hi JFB,

                Ya I tried what u advised me to solve the issue. I used DataGrid instead of Grid. But still I am facing following problems.

                1. how to relate delete method with check boxes in datagrid. I mean in my application I have checkbox as one column. User can delete multiple rows bys checking checkboxes. I have to delete those rows. By doing this one I am facing the problems.

                2. How to select mutiple rows in DataGrid .

                3.. Its not deleting multiple rows at a time . I used the following code to delete mutiple rows.

                public function deleteOtherIncome():void {
                for(var j:Number=0;j<initDG.length;j++)
                {
                if(initDG.length>0){
                initDG.removeItemAt(incomeGrid.selectedIndex);
                }
                }
                }

                But its behaving strangly mean its not deleting selected rows , its deleting different rows irrespective of selected rows .


                Thanks & Regards,
                Lalitha
                • 5. Re: deleting rows from grid --- need help
                  Level 7
                  Hi,
                  I'm afraid that you can't even select multiple rows... you need to delete
                  one row at the time.
                  Rgds

                  JFB


                  "lalson" <webforumsuser@macromedia.com> wrote in message
                  news:fclq4q$6u3$1@forums.macromedia.com...
                  > Hi JFB,
                  >
                  > Ya I tried what u advised me to solve the issue. I used DataGrid instead
                  > of
                  > Grid. But still I am facing following problems.
                  >
                  > 1. Its not deleting multiple rows at a time . I used the following code
                  > to
                  > delete mutiple rows.
                  >
                  > public function deleteOtherIncome():void {
                  > Alert.show("Selected Length" + selectedDG.length);
                  > for(var j:Number=0;j<initDG.length;j++)
                  > {
                  > //Alert.show("j -----> "+incomeGrid.selectedIndex);
                  > if(initDG.length>0){
                  >
                  > //incomeGrid.height = incomeGrid.height - 22;
                  > initDG.removeItemAt(incomeGrid.selectedIndex);
                  >
                  > }
                  > }
                  > }
                  >


                  • 6. deleting rows from grid --- need help
                    Bob Saggot Level 1
                    You should be able to delete multiple rows at a time, just remove it from whatever the dataprovider is.. a array or arraycollection, and it should automatically update.

                    try this instead, i believe whats going on is once you delete from the datagrid, the selected index is different, so once you are deleting item number 1, it collaspes and item number 1 IS what item number 2 was...

                    the fix would be something like...

                    private function selectedDataGridItems():void
                    {
                    for(how many selected items)
                    {
                    array .push(datagrid.selecteditemnum(i))//populate it with all the selected datagrid items // incorrect code you would need to look it up
                    array.sort(descending); //gets the highest number first
                    }
                    for(array.length,i++)
                    {
                    deleteitem(array );
                    }
                    }

                    deleteitem(num:number)
                    {
                    dataproviderforDataGrid.removeitemat(num);
                    }