5 Replies Latest reply on Jul 6, 2006 6:28 PM by doug777

    Adding rows and items to Grid

    doug777 Level 1
      If I add a grid to an accordion with no child pages:

      var page: Grid = new Grid();
      page.label = "Page 1";
      myAccordion.addChild(page);

      And now want to add gridrows and grid items, I can't write:

      var gr:GridRow = new GridRow();
      myAccordion[0].addChild(gr);//and have tried many other possibilities - selectedIndex - getChildAt - using an id for the grid, but can't find anything that works

      How do I address the grid that I've added to the accordion?

      Doug
        • 1. Re: Adding rows and items to Grid
          doug777 Level 1
          Okay I think I've added the row to the grid correctly by using selectedChild.

          But now how do you add the items to the rows??

          Doug
          • 2. Re: Adding rows and items to Grid
            inlineblue Level 1
            If you're going to need to refer to child components after adding them to the parent, it's easiest to simply keep a reference to them. Instead of using a local variable "page", declare a property in whatever class you're in and use that. eg:

            private var myGrid: Grid;

            //In some method:
            myGrid = new Grid();
            myAccordion.addChild(myGrid);

            In another method, you can use myGrid to get at the grid.

            As for your grid question, I really think you need to read over the documentation about data-driven controls (including the DataGrid) and learn about adding columns and setting the dataprovider.
            • 3. Re: Adding rows and items to Grid
              doug777 Level 1
              Thanks very much for your reply. I can see that having the component defined as a local variable is actually one of the problems.

              What I should have realized, but didn't was that Grid is the old DataGrid component. Using the dataProvider for this is too restrictive as I need each cell to contain data from several different sources and separately addressable.

              I think what I need is the VBox and HBox containers with Tile containers inside them and Text components inside the Tiles.

              I wish there were some AS examples using components in the Help files, but I can't find much. It seems almost exclusively mxml.

              Am I right in thinking that mxml cannot handle dynamic layouts i.e. where the contents of the parameters are variables?

              Doug

              • 4. Adding rows and items to Grid
                inlineblue Level 1
                If you mean to you want to create components at runtime, then that's what you were doing with "new" and "addChild". They're pretty straightforward to use, are they not? You can simply add Text components to a TileList and then add that to a VBox, etc.
                • 5. Re: Adding rows and items to Grid
                  doug777 Level 1
                  Yes, it's easy and I now have it all working.

                  The reason why I was finding it so difficult is that I thought you had to continually add additional children to the existing chain of parents (rather like you would in javascript) like this:-

                  myAcc.accordion_page.VBox_0.HBox_0.addChild(tile);

                  Whereas in fact the way to do it is to add all tiles to an HBox, then add each HBox (which then comes with its children automatically) to the VBox and so on and then you don't need to know how to refer to them from the top down. And in fact you can add them in any order you like as long as you just add the child to its parent directly instead of to its whole chain of parents.

                  But I would say that its not easy to guess that this is the way to do it if there are no examples and you have no prior experience.

                  Thanks very much for all your help. It is much appreciated.
                  Doug