3 Replies Latest reply on Jan 9, 2011 7:06 AM by Don Kerr

    checkbox itemrenderer with XMLList

    Don Kerr Level 3

      When my dataProvider is an ArrayCollection, I use this approach to allow the user to select an item using a checkbox


      <mx:AdvancedDataGridColumn width="20" headerText="" 

         dataField="cb" editorDataField="selected" rendererIsEditor="true" editable="true">



      <mx:CheckBox   click="data.cb=!data.cb;"  selected="{data.cb}"/>





      data.cb=!data.cb works great to toggle the data in the dataProvider.  I then save the changed cb values back to the database.


      I'd like to do something similar when my dataProvider is hierarchical XML

      myXML = event.result.Node  as XMLList;




      hierarchyDP = new HierarchicalData(myXML);


      I'd like the checkbox change to update the xml in my dataProvider so that I can later save the checked items to the database.


      It does not work if I just change it to data.@cb=!data.@cb


      <mx:AdvancedDataGridColumn width="20" headerText="" 

        dataField="@cb" editorDataField="selected" rendererIsEditor="true" editable="true">



      <mx:CheckBox   click="data.@cb=!data.@cb;"  selected="{data.@cb}"/>






      How do I update the cb property ('true' or 'false') in the current Node inside the dataProvider so I can save the changed cb values back to database?  In other words, if the xml contains cb='true', and the user unchecks the box for the current data, how do I change cb='false';



      Don Kerr

        • 1. Re: checkbox itemrenderer with XMLList
          Wrataxas Level 2

          Maybe data.@cb is a String and you need to convert it to a Boolean before negating it?


          !(data.@cb == "true")


          or perhaps


          ! Boolean( data.@cb )

          1 person found this helpful
          • 2. Re: checkbox itemrenderer with XMLList
            Gregory Lafrance Level 6

            Sometimes Boolean in itemRenderers are strange. This code answers your question:


            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                  import mx.collections.XMLListCollection;
                  [Bindable] public var xlc:XMLListCollection;
                  private function init():void{
                    xlc = new XMLListCollection(xmllist);
              <mx:XMLList id="xmllist" xmlns="">
                 <item cb='true'/>  
                <item cb='false'/>  
                <item cb='false'/>  
                <item cb='true'/>  
                <item cb='true'/>      
              <mx:AdvancedDataGrid dataProvider="{xlc}" width="100">
                  <mx:AdvancedDataGridColumn width="80"  
                        <mx:CheckBox selected="{data.@cb=='true'?true:false}" 
              <mx:TextArea id="txt" width="100%" height="100%"/>

            If this post answers your question or helps, please mark it as such. Thanks!

            Adobe Flex Development and Support Services

            • 3. Re: checkbox itemrenderer with XMLList
              Don Kerr Level 3

              Thanks Gregory!  This worked nicely.  I marked it as the answer!


              Appreciate the help.