1 Reply Latest reply on Aug 5, 2009 1:41 AM by megharajdeepak

    Problem with Checkbox ItemRenderer in a DataGrid

    megharajdeepak

      Hello Everyone,

       

      I'm using a datagrid with two columns, which is used as a data entry grid. The first column has a simple text input field and the 2nd column has a checkbox as an itemrenderer. On creationComplete event, I'm passing an arraycollection as the dataprovider for this datagrid. The arraycollection:

       

      <mx:ArrayCollection id="psAC">
              <mx:source>
                  <mx:Array>
                      <mx:Object PaText="line1" PaCheckbox="0" />
                      <mx:Object PaText="line2" PaCheckbox="0" />
                      <mx:Object PaText="line3" PaCheckbox="1" />
                      <mx:Object PaText="line4" PaCheckbox="0" />
                      <mx:Object PaText="line5" PaCheckbox="0" />
                     
                  </mx:Array>
              </mx:source>
          </mx:ArrayCollection>

       

      There is a datagrid (dGa) in the main application. On click of this, a pop up window comes up which has the same datagrid layout(i.e, 2 columns). And this is where the data is entered. Here, if the user checks the check box, I have assigned a value of '1' for the 2nd column of the arraycollection. THis code(below) works fine.

       

      <datagrid in pop up window>

      <mx:DataGridColumn headerText="Best Possible Action?" textAlign="center" width="200" editable="false">

       

                                  <mx:itemRenderer>
                                      <mx:Component>

                                         <mx:CheckBox>
                                              <mx:Script>
                                                      <![CDATA[
                                                                                                  
                                                         
                                                           override public function set data(value:Object):void{

       

                                                               if(value.PaCheckbox == 1){
                                                                  this.selected = true;
                                                              }else{
                                                                  this.selected = false;
                                                              }
                                                             
                                                            
                                                                                                                      
                                                          }
                                                         
                                                         
                                                            
                                                      ]]>
                                                  </mx:Script>
                        
                                              <!--<mx:change>
                                                  <![CDATA[
                                                      if(this.selected == true){
                                                           data.PaCheckbox = 1;
                                                          
                                                       }else{
                                                           data.PaCheckbox = 0;
                                                       }
                                                  ]]>
                                              </mx:change>-->


                                          </mx:CheckBox>
                                      </mx:Component>
                                  </mx:itemRenderer>
                              </mx:DataGridColumn>

       

      But I would also need to set the PaCheckbox value to 0 or 1, based on teh check condition of the check box. I tried using change event (commented in the code above). But there I get an error: Cannot access a property or method of a null object reference. I checekd in debug mode, there the data object is null! Can you please help me on how to pass back the values(0 o 1) to my arraycollection, based on the checkbox's status?

       

      Cheers,

      Deepak