3 Replies Latest reply on Oct 6, 2011 10:31 AM by Flex harUI

    How to set a checkbox in a datagrid's itemrenderer



      I've a spark datagrid. In a column there is a checkbox. In another column (I need to add it dynamically with actionscript) I've another checkbox (inside an itemrenderer). Cliccking on the first checkbox, I need to enable/disable the second checkbox.

      More in general I need to interact not just with a checkbox but some other components inside columns added dynamically.

      My question is: how to get (with actionscript) components inside an itemrender created dynamically?


      Follow details related to the checkbox case:


      Here my spark datagrid columns definitions:


                                    <s:GridColumn headerText="Azioni" resizable="false" sortable="false" width="49" ....../>
                                    <s:GridColumn headerText="Iscritto" width="60" itemRenderer="renderers.EventoPersonaCheckBoxRenderer" dataField="iscritto"/>
                                    <s:GridColumn id="personaEventoGridPersonaColumn" headerText="Persona" labelFunction...../>
                                    <s:GridColumn id="personaEventoGridSocietaColumn" headerText="Societa" labelFunction..../>


      As you can see there si an itemrender. A checkbox is inside it.


      I also need to add dynamically new colums to my datagrid. Each new column has an itemrender with a checkbox.


      here the code to add a new columns:


      private function createNewColumn():void
                                              var newColumn:GridColumn = new GridColumn("column TEST");
                                              newColumn.itemRenderer = new ClassFactory(NewColumnCheckBoxRenderer);
                                              var  cols:ArrayList = new ArrayList(); 
                                              cols =eventoPersonaGrid.columns as ArrayList;



      The itemrenderer is the following:


      <s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                                        xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">
                                    import events.CheckBoxEvent;
                                    protected function eventoSubscribedCB_clickHandler(event:MouseEvent):void
                                              data.iscritto = ! data.iscritto;
                                              dispatchEvent(new CheckBoxEvent(CheckBoxEvent.UPDATE,data.iscritto));
                          <s:HorizontalLayout horizontalAlign="center" verticalAlign="middle"/>
                <s:CheckBox id="eventoSubscribedCB" selected="{data.iscritto}" click="eventoSubscribedCB_clickHandler(event)"/>


      As explained above cliccking on the checkbox inside datagrid definition, I need to change the checkbox properties that is located inside an itemrenderer.

      How can I do that?

      Is there a way to get the itemrenderer and checkbox references by the selectedItem datagrid property?


      thank you