I have a XMLListCollection and I am using DataGrid to show all the 
records of the collection. 

Inside DataGrid, I need to show a checkbox using itemRenderer for one 
of the XML elements.

The documentation states that Checkbox works with boolean value BUT 
in my source XML the boolean value is in String format . 

So how to convert that String into boolean before showing records 
into DataGrid. Any other solutions will also be appreciated.

Please find the source below for a sample MXML.
a) Main.mxml  - Main Application file
b) EditorDGCheckBox.mxml - Item Renderer
 
Main.mxml
---------
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; 
xmlns:local="*">
    
    <mx:Script>
        <![CDATA[
         import mx.collections.ArrayCollection;
         import mx.collections.XMLListCollection;
         import mx.controls.Alert;
         import mx.collections.IViewCursor;
         import mx.managers.CursorManager;
            
            [Bindable] 
            public var bookList:XML = <BookList>
             <Book>
                <Name>Book1</Name>
                <Author>Author1</Author>
                <sold>true</sold>
             </Book>
             <Book>
                <Name>Book2</Name>
                <Author>Author2</Author>
                <sold>false</sold>
             </Book>
             <Book>
                <Name>Book3</Name>
                <Author>Author3</Author>
                <sold>true</sold>                
             </Book>
          </BookList>;
              
              [Bindable] 
              public var bookColl:XMLListCollection = new 
XMLListCollection(new XMLList(bookList.Book));           
             
        ]]>
    </mx:Script>
    <mx:DataGrid id="myGrid" dataProvider="{bookColl}"  
editable="true">    
        <mx:columns>
            <mx:DataGridColumn dataField="Name" editable="false"/>
            <mx:DataGridColumn dataField="Author" editable="false"/>
            <mx:DataGridColumn dataField="sold" 
width="150"                
             headerText="Sold"
             rendererIsEditor="true"
             editorDataField="cbSelected"
             itemRenderer="EditorDGCheckBox"/>
        </mx:columns>
    </mx:DataGrid>
</mx:Application>

EditorDGCheckBox.mxml
--------------------
<?xml version="1.0"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml";>
   <mx:Script>
        <![CDATA[
            // Define a property for returning the new value to the 
cell.
            public var cbSelected:Boolean;
        ]]>
    </mx:Script>
    <mx:Binding source="followUpCB.selected" 
destination="cbSelected" />
    <mx:CheckBox id="followUpCB" selected="{data.sold}" />
</mx:VBox>

Reply via email to