4 Replies Latest reply on Sep 4, 2007 1:44 AM by sivudu

    add row to Grid/Canvas dynamically

    sivudu
      Hi All,

      I am novice to flex. Recently I have started to develope prototype. Now my problem is how to add / delete a row to Grid / Canvas dynamically. I am providing two buttons add and delete . If user clicks on add button I have to add a new row to Grid / Canvas. In that row I am providing select box as one of the column. If user checks some select boxes and clicks on delete button , it should delete all rows that user has checked.

      Anybody suggest me to solve this issues. Thanx in advance.

      Thanks & Regards,
      Siva Kumar
        • 1. Re: add row to Grid/Canvas dynamically
          ThinkingProspects
          A gridrow can be added to Grid and not Canvas.

          I feel you should have taken a different approach like states. however for your current situation you can try this;

          private function addSelect():void
          {
          ///Create Combo (select in your question, if I am right)
          var combo:ComboBox = new ComboBox();

          //create grid item and add combo to it
          var gridItem:GridItem = new GridItem();
          gridItem.addChild(combo);

          //create row and add item to it
          var gridRow:GridRow = new GridRow();
          gridRow.addChild(gridItem);

          //It seems you already have the grid, say its id is grid

          grid.addChild(gridRow).
          }
          This will add the combo to Grid.

          I still feel in you current situation there should be a different way to achieve this functionality.
          • 2. Re: add row to Grid/Canvas dynamically
            sivudu Level 1
            Hi ,

            Thanx for ur reply. Actually my requirement is I have to add new row to Grid. What I did is I put the Grid inside of Canvas. ok leavae that one. Once again thanx for ur immediate reply. The u sent is just adding combobox to Grid item. How to add new row to Grid and how to delete selceted row / rows from Grid.

            Thanks & Regards,
            Siva Kumar
            • 3. Re: add row to Grid/Canvas dynamically
              ThinkingProspects Level 1
              The code snippet I have sent is basically to add the combo to grid item and then item to row and eventually row to the grid.

              Meanwhile the Grid does not have selected row property. You may like to consider dataGrid instead. though there can be work-arounds or sheepish ways to delete the rows from Grid. Important thing here is to identify which row is selected.

              For example, if user has chosen some checkbox in a row then you may like to pass the id of the row with the values so that you can delete that row by saying grid.removeChild(rowid)

              • 4. Re: add row to Grid/Canvas dynamically
                sivudu Level 1
                Hi,

                Thanx for ur suggestions. ok I got some idea on how to add and delete rows to Grid. Anyhow I will get back if I face any problems when I am doing. I am greatful to u.

                Thanks & Regards,
                Siva Kumar