5 Replies Latest reply on May 21, 2009 9:19 AM by Miggl

    Removing GridRow dynamically?

    Miggl Level 1

      I would like to remove a GridRow from a Grid object dynamically via a button in the GridRow itself. Can I tell the GridRow to kill itself and remove itself from its parent? Or do I need to reference the parent and have it kill the row, and if so, how do I determine the id of the row of the button I am clicking on?

       

      Thanks again!

      -Mike

        • 1. Re: Removing GridRow dynamically?
          Miggl Level 1

          One solution I just discovered is the following:

          (this.parent as Grid).removeChild(this);
          

          Using this from within the GridRow object seems to work. Is this the best way of achieving my goal?

           

          Thanks!

          • 2. Re: Removing GridRow dynamically?
            Michael Borbor Level 4

            Could you post a bit more of your code?

            • 3. Re: Removing GridRow dynamically?
              Miggl Level 1

              Sure:

               

              In the App:

              <mx:Grid>
                   <custom:MyGridRow />
              </mx:Grid>
              

               

               

              And then in MyGridRow.mxml:

              <mx:GridRow
                   xmlns:mx="http://www.adobe.com/2006/mxml"
              >
                   <mx:Script>
                        <![CDATA[
                             private function removeRow(event:Event):void
                             {
                                  (this.parent as Grid).removeChild(this);
                             }
                        ]]>
                   </mx:Script>
                   <mx:GridItem>
                        <mx:Button
                             label="-"
                             click="removeRow(event)"
                        />
                   </mx:GridItem>
                   <mx:GridItem>
                        <mx:Label
                             text="Hello"
                        />
                   </mx:GridItem>
              </mx:GridRow>
              
              • 4. Re: Removing GridRow dynamically?
                Michael Borbor Level 4

                I came up with this I don't think is nicer than your version just another way to go.

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
                                    xmlns:custom="*">
                     <mx:Script>
                          <![CDATA[
                               private function myClickHandler(e:MouseEvent):void{
                                    
                                    myGrid.removeChild(e.target.parent.parent);
                               }
                          ]]>
                     </mx:Script>
                     <mx:Grid id="myGrid" click="myClickHandler(event)">
                          <custom:CustomRow />
                          <custom:CustomRow />
                          <custom:CustomRow />
                     </mx:Grid>
                
                </mx:Application>
                
                • 5. Re: Removing GridRow dynamically?
                  Miggl Level 1

                  Hi Michael,

                   

                  Thanks for your alternate example. I was thinking about this some more over the night and came to the conclusion that I should be doing this using events. The GridRow should dispatch an event, that is then caught in the Grid component.

                  The reason I am now thinking this route is because the GridRow component wil always have this feature when used with this Grid component, and that using events is perhaps more in line with the FLEX methodology (I sometimes unintentionally revert back to procedural methodology, or standard OOP, and not event-based methodology).

                   

                  Thoughts?

                  -Mike