5 Replies Latest reply on Aug 3, 2009 3:32 AM by nikos101

    Checkboxes in ADG are acting like radiobuttons only letting me select one checkbox at a time

    nikos101 Level 2

      I have the following AdvancedDataGridColumn

       

      <mx:AdvancedDataGridColumn width="35" itemEditor="CheckBoxRenderer" itemRenderer="CheckBoxRenderer" showDataTips="true" editable="false">

       

       

       

                                  </mx:AdvancedDataGridColumn>

       

      However the checkboxes are acting like radiobuttons only letting me select one checkbox at a time. Any ideas how to fix this?

        • 1. Re: Checkboxes in ADG are acting like radiobuttons only letting me select one checkbox at a time
          ShardulSingh Level 3

          Hi,

          Pls use itemRenderer instead of itemEditor it will work perfectly.

           

           

           

          Remove ItemEditor from here.

           

           

           

           

          with Regards,

          Shardul Singh Bartwal

          • 2. Re: Checkboxes in ADG are acting like radiobuttons only letting me select one checkbox at a time
            nikos101 Level 2

            Thanks, I just tested it and I'm still having the same problem

             

                <mx:AdvancedDataGridColumn width="35" itemRenderer="CheckBoxRenderer" showDataTips="true" editable="false">



                                        </mx:AdvancedDataGridColumn>

            • 3. Re: Checkboxes in ADG are acting like radiobuttons only letting me select one checkbox at a time
              nikos101 Level 2

              heres the code for the CheckBoxRenderer

               

              package
              {
              import flash.display.DisplayObject;
              import flash.events.KeyboardEvent;
              import flash.events.MouseEvent;
              import flash.text.TextField;
              import mx.controls.CheckBox;
              import mx.controls.advancedDataGridClasses.AdvancedDataGridListData;
              import mx.controls.listClasses.ListBase;

               

              /**
              *  The Renderer.
              */
              public class CheckBoxRenderer extends CheckBox
              {

               

                  public function CheckBoxRenderer()
                  {
                      focusEnabled = false;
                  }

               

                  override public function set data(value:Object):void
                  {
                      super.data = value;
                      if(data != null){
                      super.data.isSelected = false;
                      }
                      this.selected = false;
                      invalidateProperties();
                  }
                 
                  override protected function commitProperties():void
                  {
                      super.commitProperties();
                      if (owner is ListBase)
                          selected = ListBase(owner).isItemSelected(data);
                  }

               

                  /* eat keyboard events, the underlying list will handle them */
                  override protected function keyDownHandler(event:KeyboardEvent):void
                  {
                  }

               

                  /* eat keyboard events, the underlying list will handle them */
                  override protected function keyUpHandler(event:KeyboardEvent):void
                  {
                  }

               

                  /* eat mouse events, the underlying list will handle them */
                  override protected function clickHandler(event:MouseEvent):void
                  {
                        super.clickHandler(event);
                     
                      if(!data.isSelected){
                          data.isSelected = true;
                      }else{
                          data.isSelected = false;
                      }
                  }

               

                  /* 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 AdvancedDataGridListData)
                      {
                          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 = 0;
                              }
                          }
                      }
                  }

               

              }

               

              }

              • 4. Re: Checkboxes in ADG are acting like radiobuttons only letting me select one checkbox at a time
                nikos101 Level 2

                This line of code is the prblem

                 

                but I don't know why

                 

                override public function set data(value:Object):void
                    {
                        super.data = value;
                        if(data != null){
                        super.data.isSelected = false;
                        }
                        this.selected = false;
                        invalidateProperties();
                    }

                • 5. Re: Checkboxes in ADG are acting like radiobuttons only letting me select one checkbox at a time
                  nikos101 Level 2

                  this code fixed it

                   

                       override public function set data(value:Object):void
                      {
                         
                         
                          super.data = value;
                         
                          if(super.data.isSelected == null){
                              data.isSelected = false;
                          }
                         
                          data.isSelected = this.selected;
                         
                          invalidateProperties();
                      }