9 Replies Latest reply on Sep 12, 2011 9:06 AM by puddytat5000

    datagrid addchild()

    puddytat5000 Level 1

      when I use the addchild() method of a datagrid, I expect to see the newly added component inside the datagrid, but it is not visible. How do I get the newly added child to show?

        • 1. Re: datagrid addchild()
          FlashGuruWiz

          Post the code for examination...


          • 2. Re: datagrid addchild()
            puddytat5000 Level 1

            <?xml version="1.0" encoding="utf-8"?>

            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

             

            <mx:Script>

            <![CDATA[

            import mx.controls.Label;

             

            private function addDGChild():void {

            var L:Label = new Label();

             

            L.name = 'my_label_name';

            L.text = 'my Text';

             

            myDG.addChild(L);

            }

             

            ]]>

            </mx:Script>

            <mx:Button id="mybutton" x="0" y="0" label="Button" click="addDGChild()"/>

             

            <mx:DataGrid x="127" y="99" id="myDG">

             

            </mx:DataGrid>

             

             

            </mx:Application>

            • 3. Re: datagrid addchild()
              drkstr_1 Level 4

              What exactly are you hoping would magically happen when you run this code? Where do you expect the child to show up? The DataGrid is a component, not a container. The display code of the component is intended for rendering the chrome, header, and item renderers.

               

              Wrap or extend the DataGrid into a custom component that achieves your desired design goals.

              • 4. Re: datagrid addchild()
                puddytat5000 Level 1

                shut up and take ur smarmy response elseware cause ur talking rubbish

                • 5. Re: datagrid addchild()
                  puddytat5000 Level 1

                  Why does this work however?

                   

                  <?xml version="1.0" encoding="utf-8"?>

                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

                   

                  <mx:Script>

                  <![CDATA[

                  import mx.controls.Label;

                   

                  private function addDGChild():void {

                  var L:Label = new Label();

                   

                  L.name = 'my_label_name';

                  L.text = 'my Text';

                   

                  addChild(L);

                  validateNow();

                  myDG.addChild(L);

                   

                  }

                   

                  ]]>

                  </mx:Script>

                  <mx:Button id="mybutton" x="0" y="0" label="Button" click="addDGChild()"/>

                  <mx:DataGrid x="127" y="99" id="myDG"></mx:DataGrid>

                   

                  </mx:Application>

                  • 6. Re: datagrid addchild()
                    Flex harUI Adobe Employee

                    Because DarkStar was right.  I think you owe him/her an apology.

                     

                    There are different rules for container vs components in Flex, especially in

                    the MX components. MX containers are bound to a layout and apply the layout

                    to their children.  MX components have custom layouts so if you give them

                    additional children they won't position or size them, which means the label

                    will default to zero width/height and not show anything.

                     

                    For both components and containers, parents size their children.

                     

                    By adding to the app and forcing validation, the Label was given a size, so

                    when you reparent it, it will keep its size.

                     

                    It is not a recommended practice to add components to other components

                    unless you are subclassing and overriding the layout and measurement

                    lifecycle methods.  But as you found, you can certainly make it work if you

                    want to.  You can size and posiiton the Label via setActualSize and

                    getExplcitOrMeasuredWidth/Height if you want to skip adding to a container

                    and forcing validation.

                    1 person found this helpful
                    • 7. Re: datagrid addchild()
                      puddytat5000 Level 1

                      Thanks for ur help. I needed to to do this to display function buttons in the datagrid when and item is rolled over, and it now works perfectly.

                       

                      I will not apologized as the tone that he/she used was unnecessary + he/she seemed to b suggesting it was not possible which it was. I was not asking about recommended practices but simple needed to a quick way to do what I intended.

                      • 8. Re: datagrid addchild()
                        drkstr_1 Level 4

                        I apologize if my tone sounded kurt, but I think you read more in my post than was actually there. I am a very literal person, and when I said "what were you hoping would happen...", I did not intend that as a rhetorical question. Given the complex nature of a DataGrid, there could be many possible things one would hope to accomplish by adding a child to it (I actually assumed you were trying to add a footer, which was not the case). I was simply trying to understand the problem before advising on a way to solve it. Anyways, glad you got it sorted out.

                         

                        Cheers!

                        1 person found this helpful
                        • 9. Re: datagrid addchild()
                          puddytat5000 Level 1

                           

                          In that case apology accepted, and I am sorry if I took it in a wrong way to how it was meant, I guess too often in forums I see pompous and unhelpful replies being given and took this for one of those times.

                           

                          Anyway  thanks for trying to help.

                           

                          Also I had already extended the datagrid to include a footer but this was something I did not see any sense in extending it further for.