0 Replies Latest reply on Oct 22, 2009 3:28 AM by timo888

    ActionScript: how to restrict itemRenderer to a specific column in CheckBoxDataGrid ?

    timo888

      My code (snippet given at bottom) doesn't work but I've not been able to find an example of how to add the checkboxrenderer column and other columns in ActionScript, and restrict the itemRenderer to the column to which it has been attached.

       

      I've got it working in mxml fine, but I need to encapsulate a checkboxgrid in a TitleWindow which is being popped up, and the class is passed several arguments, so I'd like to do it in AS rather than mxml.

       

      I am getting this error:

      TypeError: Error #1034: Type Coercion failed: cannot convert mx.controls.dataGridClasses::DataGridItemRenderer@8b180a1 to mx.controls.CheckBox.

      at CheckBoxDataGrid/drawItem()

       

       

      The itemRenderer is being applied to a column other than the one to which it has been associated, so apparently (I'm new at Flex) it is as though the itemRenderer is attached to all the grid 's columns even though I assign it to just one of them. The following ActionScript is not the equivalent of the mxml:

       

      var selcol:DataGridColumn=new DataGridColumn;
      selcol.itemRenderer= new ClassFactory(CheckBoxRenderer); 
      // CheckBoxRenderer is Alex's Harui's class


      <OEGUI:CheckBoxDataGrid id="HitsGrid" height="90%" width="100%" allowMultipleSelection="true" itemClick="onHitsGridRowClick(event);">
      <OEGUI:columns>
      <mx:DataGridColumn headerText="show" editable="true" draggable="false"  sortable="false" itemRenderer="OEGUI.CheckBoxRenderer" />

       

       

      <snippet>

      import mx.core.ClassFactory

      .

      . <snip>

      .

       

      private var grid: CheckBoxDataGrid= new CheckBoxDataGrid;

      grid.allowMultipleSelection=true;


      var selcol:DataGridColumn=new DataGridColumn;
      selcol.itemRenderer= new ClassFactory(CheckBoxRenderer);  
      // CheckBoxRenderer is Alex's Harui's class
      selcol.editable=true;
      selcol.draggable=false;
      selcol.sortable=false;

      selcol.headerText="show";
      grid.columns.push(selcol);
                 
                 
      var idcol:DataGridColumn = new DataGridColumn;    

      idcol.dataField="wrdid";

      idcol.visible=false;

      idcol.headerText="id";
      grid.columns.push(idcol);
                 
      var wordcol:DataGridColumn=new DataGridColumn;
      wordcol.dataField="spelling";

      wordcol.headerText="spelling";


        grid.columns.push(wordcol);