2 Replies Latest reply on Feb 11, 2008 4:33 PM by ntsiii

    chechbox check all

    GeorgeWS Level 1
      I am having trouble checking all of the checkboxs in a datagrid. This is what I have:

      <mx:Script>
      <![CDATA[

      [Bindable] public var myChecks:Array;
      private function selectAll():void{
      myChecks.checked = true
      }
      ]]>
      </mx:Script>

      <mx:Button label="Check All" click="selectAll();"/>

      <mx:DataGrid id="myDataGrid" dataProvider="{myAccounts}" width="100%" height="100%" themeColor="#73B9B9">
      <mx:columns>
      <mx:DataGridColumn headerText="Include" dataField="Include" width="58" sortable="false">

      <mx:itemRenderer>
      <mx:Component>
      <mx:HBox horizontalAlign="center">
      <mx:CheckBox id="myChecks" click="data.Include=!data.Include" selected="{data.Include}" themeColor="#73B9B9"/>
      </mx:HBox>
      </mx:Component>
      </mx:itemRenderer>

      </mx:DataGridColumn>
      </mx:columns>
      </mx:DataGrid>

      I get this error:
      Cannot access a property or method of a null object reference

      Im thinking I can just have the selected attribute of the checkbox get set to true, all of the checkbox will be set to true? I probably will need to uncheck all also.

      Thanks

      George
        • 1. Re: chechbox check all
          Arty13
          The reason I think you are getting that error is because you are declaring an Array called myChecks and then you are trying to access the "checked" value of it. And an Array does not have that value.

          So in your selectAll() function, you are accessing the Array and not the checkbox.

          Hope this helps you figure it out.

          Art
          • 2. Re: chechbox check all
            ntsiii Level 3
            You must control all itemRenderers through the dataProvider. George, you know this.

            Do a for-in loop over "myAccounts", set the .include=true on each item.

            Then either re-assign the data provider to the DG, or try calling itemUpdated() on the collection.

            Tracy