I have a column in a datagrid using CheckBox as itemRender, and user 
checks CheckBoxes they want to send email for.

But after user checks the CheckBoxes, the data provider has not been 
updated.

Should I try to get the dataProvider to get the updated 
checked/unchecked state of the CheckBoxes (and if so, how), or should 
I simply examine the "selected" property of each of the Checkboxes 
(and if so, how).

Someone in the Adobe Flex forum suggested in CheckBox you have to 
add "change" event handler and when it is called set the property.
change="data.sendEmail = chk_box_id.selected", but Flex prevents me 
from using an ID in this case for the itemrenderer CheckBox.

I tried this but then the checkBox does not get checked when you 
click it:

change="data.sendEmail=this.selected" 

Thanks very much. Greg

------------- data/contactsTest.xml ------
<?xml version="1.0" encoding="utf-8" ?>
<contacts>
  <contact>
    <name>Frank Bords</name>
    <sendEmail>false</sendEmail>
  </contact>
  <contact>
    <name>Dave Harris</name>
    <sendEmail>false</sendEmail>
  </contact>
  <contact>
    <name>Lee Travis</name>
    <sendEmail>false</sendEmail>
  </contact>
  <contact>
    <name>Glen Matin</name>
    <sendEmail>false</sendEmail>
  </contact>
  <contact>
    <name>Gary Curtis</name>
    <sendEmail>false</sendEmail>
  </contact>
</contacts>
--- Test.mxml ---
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
  creationComplete="init()">
  <mx:Script>
    <![CDATA[
      import mx.rpc.events.ResultEvent;
      import mx.collections.XMLListCollection;
      import mx.controls.DataGrid;

      [Bindable]
      private var contactData:XMLListCollection;
      
      private function init():void {
        contactService.send();
      }

      private function sendEmail(event:MouseEvent):void{
        for each(var item:XML in contacts.dataProvider){
          trace(item.sendEmail);
        }
      }
      
      private function contactResultHandler(event:ResultEvent):void{
        contactData = new XMLListCollection
(event.result.contact);        
      }
    ]]>
  </mx:Script>
  <mx:HTTPService id="contactService" url="data/contactTest.xml" 
resultFormat="e4x"
    useProxy="false" result="contactResultHandler(event)"/>
  <mx:DataGrid id="contacts" dataProvider="{contactData}" 
rowCount="5">
    <mx:columns>
      <mx:DataGridColumn dataField="name" headerText="Name" 
width="100"/>
      <mx:DataGridColumn dataField="sendEmail" headerText="Email 
Contacts" width="100"
        rendererIsEditor="true">
        <mx:itemRenderer>
          <mx:Component>
            <mx:CheckBox label="Send Email" 
selectedField="{data.sendEmail as Boolean}"
change="data.sendEmail=this.selected" 
              paddingLeft="5"/>
          </mx:Component>
        </mx:itemRenderer>              
      </mx:DataGridColumn>
    </mx:columns>
  </mx:DataGrid>        
  <mx:Button label="Email Checked Contacts" fontSize="14" 
color="0xAB45C4"
    click="sendEmail(event)"/>
</mx:Application>


Reply via email to