1 Reply Latest reply on Apr 16, 2008 8:39 AM by GeorgeWS

    Select all checkboxes in datagrid via code

    p_repetti
      I have created a DataGrid component whose last column is rendered/edited with a checkbox. This checks whether the row data will be sent to the server or not.
      Rather than forcing the user to check all of the rows manually, I have a "Select All" button which commands the selection of all the checkboxes in that column.
      My problem is that I can't write the code to implement the selection. It is AS code most likely, but I could not find an example going through docs/forums/whatever.
      How do I loop over the DataGridColumn object to get the CheckBox instances ?

      Can anyone point me to useful examples/references ?

      I am using Flex 3 SDK, by the way.

      Thanks
        • 1. Re: Select all checkboxes in datagrid via code
          GeorgeWS Level 1
          Im doing this:

          private function selectAll():void {
          var length : int = myDataGrid.dataProvider.length;
          for( var i : int = 0; i < length; i++ )
          {
          var item : Object = myAccounts.getItemAt( i );
          item["Include"] = '1';
          }
          myAccounts.refresh();
          }

          Include is my column of checkboxs in my datagrid

          <mx:DataGridColumn headerText="Include" dataField="Include" width="58" sortable="false">

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

          </mx:DataGridColumn>