1 Reply Latest reply on Apr 23, 2007 2:45 PM by VarioPegged

    old problem: the render CheckBox works wrong.

    01robert

      hi all,

      [I posted this question several days ago, but have not gotten the answer. I think I did not make the problem clear. So repost it again]

      I put a checkBox as a datagrid's render, it works well at the first time. After I changed the selectedValue and refresh the datagrid, It selected the checkboxes randomly.

      Any suggestion will be appreciated!


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:DataGrid x="177" y="68" dataProvider="{myList}" editable="true">
      <mx:columns>
      <mx:DataGridColumn headerText="name" dataField="name"/>
      <mx:DataGridColumn headerText="isTrue" dataField="isTrue"/>
      <mx:DataGridColumn headerText="isTrue" dataField="isTrue"
      itemRenderer="mx.controls.CheckBox"
      rendererIsEditor="true" editorDataField="selected"
      />
      <!--rendererIsEditor="true" editorDataField="selected"-->
      </mx:columns>
      </mx:DataGrid>
      <mx:Button label="refresh" click="resetList()" x="240" y="38"/>
      <mx:Script>
      <![CDATA[
      import mx.controls.CheckBox;
      import mx.collections.ArrayCollection;
      [Bindable]
      private var myList:ArrayCollection=new ArrayCollection();

      private function resetList():void{
      var arr:Array=[{name:"test1", isSelected:true}
      ,{name:"test3", isTrue:true}
      ,{name:"test2", isTrue:true}];
      myList=new ArrayCollection(arr);
      }
      ]]>
      </mx:Script>
      </mx:Application>
        • 1. old problem: the render CheckBox works wrong.
          VarioPegged Level 2
          Here's a solution that may work for you. It uses a value object's "isTrue" property to bind to your Checkbox's "selected" property. This solution is almost exactly Derrick Grigg's Checkbox solution, with the exception of instantiating the VOs in a for loop from your original array.

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="resetList();">

          <mx:Script>
          <![CDATA[

          import mx.collections.ArrayCollection;
          import valueobjects.ValueObject;

          [Bindable]
          private var myList:ArrayCollection;

          private function resetList():void{

          var arr:Array = [{name:"test1",isTrue:true}, {name:"test3",isTrue:true}, {name:"test2",isTrue:true}];

          myList = new ArrayCollection()

          var myItem:ValueObject;

          var len:int = arr.length;

          for (var c:int=0;c<len;c++) {
          myItem = new ValueObject();
          myItem.name = arr[c].name;
          myItem.isTrue = arr[c].isTrue;
          myList.addItem(myItem);
          }
          }

          ]]>
          </mx:Script>

          <mx:DataGrid x="177" y="68" dataProvider="{myList}">
          <mx:columns>
          <mx:DataGridColumn headerText="name" dataField="name"/>
          <mx:DataGridColumn headerText="isTrue" dataField="isTrue"/>
          <mx:DataGridColumn headerText="isTrue" dataField="isTrue">
          <mx:itemRenderer>
          <mx:Component>
          <mx:CheckBox click="data.isTrue=!data.isTrue" selected="{data.isTrue}" />
          </mx:Component>
          </mx:itemRenderer>
          </mx:DataGridColumn>
          </mx:columns>
          </mx:DataGrid>


          <mx:Button label="refresh" click="resetList()" x="240" y="38"/>

          </mx:Application>
          =============================

          and the ValueObject class is something simple like (saved as ValueObject.as in package valueobjects):

          =============================
          package valueobjects
          {

          [Bindable]
          public class ValueObject
          {
          public var name: String;
          public var isTrue: Boolean = false;

          public function ValueObject()
          {

          }
          }
          }

          Hope that works for you