1 Reply Latest reply on Oct 25, 2010 3:40 PM by rtalton

    CheckBox Item Renderer checks wrong grid row after sorting

    iamcootis Level 1

      I have an advanced Data Grid that has a checkBox ItemRenderer. The underlying object being displayed (Server) in the dataGrid is being bound to the checkBox with a selectedForDeployment:Boolean property.


      I had this working just fine until the datagrid is sorted. After the grid is sorted I can click on the checkBox in row 2 and the checkBox in row 8 will be selected for instance. Or in some cases all checkBoxes will become checked. Also, if I have some already checked and then sort, the checkBox will become unchecked.

       

      I have an example of my itemRender below. Any idea on how I can get this to work:

       

      public class CheckBoxRenderer extends CheckBox
          {
             
             
              override public function set data(value:Object):void {
                  if(value){
                      super.data = value;
                      Server(super.data).addEventListener("setSelectionChanged", valueChange);
                      this.selected = value.selectedForDeployment;
                     
                  }   
              }
             
              public function CheckBoxRenderer(){
                  focusEnabled = false;
                  BindingUtils.bindSetter(selectionChange, this, "selected");
              }
             
              //this method occurs the checkbox is clicked
              public function selectionChange(value:Boolean):void{
                  trace(value);
                  this.selected = value;
                  if(this.data){
                      this.data.selectedForDeployment = value;
                  }
              }
             
              //This method occurs when the selectedForDeployment boolean in the object changes
              public function valueChange(event:Event):void{
                  this.selected = event.target.selectedForDeployment;
              }
             
              /* center the checkbox if we're in a datagrid */
              override protected function updateDisplayList(w:Number, h:Number):void
              {
                  super.updateDisplayList(w, h);
                 
                  if (listData is DataGridListData)
                  {
                      var n:int = numChildren;
                      for (var i:int = 0; i < n; i++)
                      {
                          var c:DisplayObject = getChildAt(i);
                          if (!(c is TextField))
                          {
                              c.x = (w - c.width) / 2;
                              c.y = (h - c.height) / 2;
                          }
                      }
                  }   
              }   
          }

        • 1. Re: CheckBox Item Renderer checks wrong grid row after sorting
          rtalton Level 4

          This usually works for me:

           

          package renderers
          {
              import flash.events.Event;   
              import mx.controls.CheckBox;

           

              public class CheckBoxRenderer extends CheckBox
              {
                  public function CheckBoxRenderer()
                  {
                      super();
                      addEventListener(Event.CHANGE, handleChange);
                  }

           

                  override public function set data(value:Object):void {
                      if(value){
                          super.data = value;
                          selected = value.selectedForDeployment;
                      }  
                  }
                 
                  private function handleChange(event:Event):void{
                      data.selectedForDeployment = event.target.selected;
                  }

           

                 
              }
          }

          1 person found this helpful