This is a quick and dirty way to do it. If I had more time I would have
decoupled the renderer from the application with a custom event but this
does work...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application pageTitle="Testing"
xmlns:mx="http://www.adobe.com/2006/mxml";
  width="100%" height="100%" backgroundSize="100%" layout="vertical"
horizontalAlign="left"
  xmlns:custom="customcomponents.*" backgroundColor="#BBDDDD"
creationComplete="onCreationComplete(event)">
     <mx:Script>
         <![CDATA[
             import mx.collections.ArrayCollection;
             import mx.rpc.events.FaultEvent;
             import mx.rpc.events.ResultEvent;
             import mx.rpc.remoting.RemoteObject;
             import mx.utils.ArrayUtil;
             import mx.events.FlexEvent;
             import mx.controls.Alert;

             [Bindable] private var itemsArrayCollection:ArrayCollection;
             private var myService:RemoteObject;
             private var itemsToDelete:Array = new Array();

             public function onCreationComplete(event:FlexEvent):void
             {
                 myService = new RemoteObject("myDestination");
                 myService.requestTimeout = 30;
                 myService.addEventListener(FaultEvent.FAULT,
faultHandler);
                
myService.getFormFields.addEventListener(ResultEvent.RESULT,
getItemsResultHandler);

                 myService.getFormFields("27");
             }

             private function
getItemsResultHandler(event:ResultEvent):void
             {
                 itemsArrayCollection = new
ArrayCollection(ArrayUtil.toArray(event.result));
                 itemsDataGrid.rowCount = (event.result as Array).length;
             }

             private function faultHandler(fault:FaultEvent):void
             {
                 switch(fault.fault.faultCode.toString())
                 {
                     case "Client.Error.RequestTimeout":
                          Alert.show("The server is not responding.
Please check that you are connected and the server is running.", "Server
Timeout");
                        break;
                     default:
                         Alert.show(fault.fault.faultString,
fault.fault.faultCode.toString());
                     break;
                 }
             }

             public function addItemToDelete(itemToDelete:String):void
             {
                 itemsToDelete.push(itemToDelete)
             }

             public function removeItemToDelete(itemToRemove:String):void
             {
                 for(var i:int ; i < itemsToDelete.length ; i++)
                 {
                     if(itemsToDelete[i] == itemToRemove)
                     {
                         itemsToDelete.splice(i, 1);
                     }
                 }
             }

             public function showItemsToDelete():void
             {
                 var alertText:String = "";
                 for(var i:int ; i < itemsToDelete.length ; i++)
                 {
                     alertText += itemsToDelete[i] + ", ";
                 }
                 Alert.show(alertText);
             }
         ]]>
     </mx:Script>

     <mx:DataGrid dataProvider="{itemsArrayCollection}"
id="itemsDataGrid">
         <mx:columns>
             <mx:DataGridColumn id="fieldNameColumn" headerText="Name"
dataField="FieldName" width="150" sortable="false" textAlign="left"/>
             <mx:DataGridColumn id="fieldLabelColumn" headerText="Label"
dataField="FieldLabel" width="350" sortable="false" textAlign="left"/>
             <mx:DataGridColumn id="fieldTypeColumn" headerText="Type"
dataField="FieldType" width="80" sortable="false" textAlign="left"/>
             <mx:DataGridColumn id="requiredColumn" headerText="Required"
dataField="Required" width="60" sortable="false" textAlign="center"/>
             <mx:DataGridColumn id="fieldOrderColumn" headerText="Order"
dataField="FieldOrder" width="50" sortable="false" textAlign="center"/>
             <mx:DataGridColumn id="fieldDeleteColumn"
headerText="Remove" dataField="FieldID" width="60" sortable="false"
textAlign="center" itemRenderer="renderers.RemoveItemCheckBox"/>
         </mx:columns>
     </mx:DataGrid>
     <mx:Button id="showItems" label="Show Items To Delete"
click="showItemsToDelete()" />
</mx:Application>


renderers.RemoveItemCheckBox
<?xml version="1.0" encoding="utf-8"?>
<mx:CheckBox xmlns:mx="http://www.adobe.com/2006/mxml";
click="onClick(event)">
     <mx:Script>
         <![CDATA[
             import mx.events.ListEvent;
             import mx.controls.dataGridClasses.DataGridListData;
             import mx.controls.Alert;
             import mx.core.Application;

             private var itemID:String;

             override public function set data(value:Object):void
             {
                 super.data = value;
                 itemID = value[DataGridListData(listData).dataField];
             }

             private function onClick(event:MouseEvent):void
             {
                 if(this.selected)
                 {
                     Application.application.addItemToDelete(itemID);
                 }
                 else
                 {
                     Application.application.removeItemToDelete(itemID);
                 }
             }
         ]]>
     </mx:Script>
</mx:CheckBox>



--- In [email protected], "crumpelfungus" <[EMAIL PROTECTED]>
wrote:
>
> Having looked through the archived topics, I was unable to find
> anything relevant, but if anyone knows of an existing thread or
> tutorial, just post the link.
>
> Basically, I am retrieving information from a MySQL database and
> dsiplay it in a datagrid. And I'm using a customized component via the
> DataGrid's itemRenderer to show a check box in the last column.
>
> In my particular case, the checkbox will indicate which records need
to
> get deleted.
>
> Is there anyone who's done something similar? And would be willing to
> share the code? With the custom component from Flex Monkey Patches
> (http://snipurl.com/3m7be), I can get the checkbox dropped in, but I
> don't know how to "trap" the CLICK in the main application to
determine
> whether the checkbox is selected or not.
>
> Anyone?
>

Reply via email to