1 Reply Latest reply on Aug 24, 2010 11:27 PM by BhaskerChari

    How to enable/disable a button by cheking the change state of checkbox in header renderer

    Sonunew2flex Level 1

      Hi Friends,

       

       

      How can i enable/disable a button in my main application when the check box in headere renderer changes.

       

      if check box is false then i have to make one button visible false. else true.

       

      I am using a header renderer in datagrid like this

       

                      <mx:DataGridColumn dataField="SEL" width="35" headerText=""
                      headerRenderer="CheckBoxHeaderRenderer"  editable="true" textAlign="center">
                      <mx:itemRenderer>
                              <mx:Component>
                                  <mx:VBox clipContent="false" horizontalAlign="center" verticalAlign="middle">
                                      <mx:CheckBox selected="{data.SEL}" click="parentDocument.selectrow(data.SEL=!data.SEL)"/>
                                  </mx:VBox>
                              </mx:Component>
                      </mx:itemRenderer>
                      </mx:DataGridColumn>

       

      and my header renderer file is like this

       

      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
          implements="mx.controls.listClasses.IDropInListItemRenderer"
          creationComplete="onComplete()">
         
          <mx:Script>
              <![CDATA[
                  import mx.controls.Button;
                  import mx.binding.utils.BindingUtils;
                  import mx.events.CollectionEvent;
                  import mx.controls.dataGridClasses.DataGridListData;
                  import mx.collections.ArrayCollection;
                  import mx.controls.DataGrid;
                  import mx.controls.dataGridClasses.DataGridColumn;
                  import mx.controls.listClasses.BaseListData;
                 
                  private var _listData:BaseListData;
                  private var _dataGrid:DataGrid;
                  private var _dataField:String;
                  [Bindable] private var _CBselected:Boolean;
                  [Bindable] private var _headerLabel:String;
                 
                  private function onComplete():void {
                      //cb.setStyle("fontWeight", this.getStyle("fontWeight"));
                  }
                 
                  [Bindable("dataChange")]
                  public function get listData():BaseListData
                  {
                      return _listData;
                  }
             
                  public function set listData(value:BaseListData):void
                  {
                      _listData = value;
                      _dataGrid = value.owner as DataGrid;
                      _dataField = (value as DataGridListData).dataField;
                      _headerLabel = value.label;
                  }
                 
                  override public function set data(value:Object):void {
                      super.data = value;
                     
                      var column:DataGridColumn = value as DataGridColumn;
                      column.sortable = false;
                     
                      checkForSelectedItems();
                  }
                 
                  private function checkForSelectedItems():void {
                      var dp:ArrayCollection = _dataGrid.dataProvider as ArrayCollection;
                      var n:Number = 0;
                      for(var i:int=0 ; i < dp.length ; i++){
                          if(dp[i][_dataField])
                              n++
                      }
                      if(n == dp.length){
                          _CBselected = true;
                      }
                  }
                 
                  private function onCBchange(event:Event):void {
                      var dp:ArrayCollection = _dataGrid.dataProvider as ArrayCollection;
                     
                      for(var i:int=0 ; i < dp.length ; i++){
                          dp[i][_dataField] = cb.selected;
                      }
                      _dataGrid.invalidateList();
                 
                  }
                 
              ]]>
          </mx:Script>
          <mx:CheckBox id="cb" horizontalCenter="0" label="{_headerLabel}"
              change="onCBchange(event)" selected="{_CBselected}" />
      </mx:Canvas>

       

       

      if(cb.selected=true)

      {

         then i have to enable a button in main mxml file

      }

      else

      {

         i have to disable the  button.

      }

       

      also how can i get the count from this header renderer file to main.mxml?

       

       

      Thanks & Regards

      sunilkumar

      7760528987