2 Replies Latest reply on Jun 12, 2007 10:46 PM by Peter_Connolly

    Unexpected (Bug?) Compile error when DataGridColumn has 'id' in Repeater

    Peter_Connolly
      When I attempt to create a small number of DataGrid controls with a Repeater, I get the following compile error message:

      Unable to generate initialization code within Repeater, due to id or data binding on a component that is not a visual child.

      Here is the minimal amount of MXML that generates the compile error:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:ArrayCollection id="myAC"/>
      <mx:ArrayCollection id="headersAC" source="{headers.header}"/>
      <mx:Model id="headers">
      <headers>
      <header>Header 1</header>
      <header>Header 2</header>
      <header>Header 3</header>
      <header>Header 4</header>
      </headers>
      </mx:Model>
      <mx:VBox>
      <mx:HBox>
      <mx:Repeater id="repeater1" dataProvider="{headersAC}">
      <mx:DataGrid id="datagrid1" width="125" height="210"
      dataProvider="{myAC}">
      <mx:columns>
      <mx:DataGridColumn id="anything" headerText="{repeater1.currentItem.header}"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:Repeater>
      </mx:HBox>
      </mx:VBox>
      </mx:Application>

      <mx:DataGridColumn/> compiles correctly.
      <mx:DataGridColumn id="anything"/> receives the compile error message above.
      <mx:DataGridColumn headerText="{repeater1.currentItem.header}"/> receives the compile error message above.

      I'd like to be able to address the repeating DataGridColumns via their id array. I'd also like to be able to assign the headerText to each of the DataGridColumns at initialization.

      There is a claim of a workaround at Nischal's blog: Referencing components inside the mx:Repeater, but there is no source code to show how to do this.

      He says:
      quote:


      Recently when I was working on Flex application and found that there is an issue with the columns of DataGrid, which is defined inside the repeater. Flex throws following error when you try to assign id or data binding values to DataGridColumn
      “Unable to generate initialization code within Repeater, due to id or data binding on a component that is not a visual child.”

      Which means if you want to assign dynamic value to say HeaderText of the column then you cannot use dynamically or id to assign value. Work around to this issue is to use columns array of datagrid to define the value. Click here to see the example and source code to use the column of the DataGrid.



      I'm not sure what "...use columns array of datagrid to define the value..." means.

      Any ideas on the workaround for this problem?