1 Reply Latest reply on Jan 23, 2010 12:30 PM by mw00

    DataGridColum dataField

    mw00

      Hi, how do I refer to the properties of my custom class objects within an ArrayCollection in the dataField of a DataGridColum?

       

      I have objects in an ArrayCollection of type BasketItem as below...

       

          public class BasketItem
          {
              private var itemName:String;
              private var itemValue:Number;
             
              public function BasketItem( name:String, value:Number )
              {
                  this.itemName = name;
                  this.itemValue = value;
              }

       

              public function getName():String
              {
                  return this.itemName;
              }
             
              public function getValue():Number
              {
                  return this.itemValue;
              }
          }

       

       

      And a dataGrid as below...

       

          <mx:DataGrid width="100%"
                       color="#000000"
                       verticalScrollBarStyleName="cardBasketVerticalScrollBar"
                       height="60%"
                       editable="false"
                       dataProvider="{basketModel.items}">
               
              <mx:columns>
                  <mx:DataGridColumn id="productColumn"
                                     dataField="itemName"
                                     headerText="Product"
                                     editable="false" />
                                      
                  <mx:DataGridColumn id="valueColumn"
                                     dataField="itemValue"
                                     headerText="Value"
                                     editable="false" />
              </mx:columns>
          </mx:DataGrid>

       

       

      I can see the collection filling up correctly as I add items because the scrollbar appears after I add a few items but I cannot render the name and value, any help would be appreciated.

       

      Thanks

       

      Mike.