title: Flex3 AdvancedDataGrid : how to add a new column based on existing one?
body: <p>I have a AdvancedDataGrid in flex3 (Flex 3) with 4 columns:</p>
  
  <ul>
  <li>id : int</li>
  <li>category : String</li>
  <li>name     : String</li>
  <li>isPreferred : Boolean</li>
  </ul>
  
  <p>And I would like to add a fifth column</p>
  
  <ul>
  <li><p>favorite : Image</p>
  
  <p>The value of favorite will be based on the value of isPreferred : if true, then favorite will be a read-heart-icon, if false, a grey-heart-icon.<br>
  Thanks for your help.</p></li>
  </ul>
  
  <p>Below is my code :</p>
  
  <ul>
  <li><p>the mxml content</p>
  
  <p>&lt;xml version="1.0"?&gt;<br>
  &lt;mx:Application 
   xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="init()"&gt;<br>
      &lt;mx:Script&gt;<br>
    &lt;![CDATA[<br>
    import mx.collections.ArrayCollection;<br>
    import com.test.Purchase;<br>
    [Embed(source="..\assets\coeur_rouge.png")]<br>
    public static const ICON_FAVORITE:Class;<br>
    [Embed(source="..\assets\coeur_gris.png")]<br>
    public static const ICON_NEUTRAL:Class;<br>
    [Bindable]<br>
    public var myAC:ArrayCollection = new ArrayCollection();<br>
    public function init() :void {<br>
  var aPurchase:Purchase=new Purchase();<br>
  var anotherPurchase:Purchase= new Purchase();<br>
  aPurchase.id=120;<br>
  aPurchase.category="category1";<br>
  aPurchase.name="advantage 2";<br>
  aPurchase.isPreferred=true;<br>
  myAC.addItem(aPurchase);<br>
  anotherPurchase.id=220;<br>
  anotherPurchase.category="category2";<br>
  anotherPurchase.name="Nintendo DS";<br>
  anotherPurchase.isPreferred=false;<br>
      myAC.addItem(anotherPurchase);}<br>
  ]]><br>
        &lt;/mx:Script&gt;<br>
  &lt;?mx:AdvancedDataGrid id="dg" width="500" height="150" dataProvider="{myAC}"&gt;<br>
        &lt;mx:groupedColumns&gt;<br>
        &lt;mx:AdvancedDataGridColumn dataField="id" headerText="ID" width="300"/&gt; 
        &lt;mx:AdvancedDataGridColumn dataField="category" headerText="Category" width="400"/&gt;<br>
        &lt;mx:AdvancedDataGridColumn dataField="name" headerText="Name" width="900"/&gt;<br>
        &lt;mx:AdvancedDataGridColumn headerText="Fav?" dataField="isPreferred" width="700"/&gt;<br>
        &lt;/mx:groupedColumns&gt;<br>
        &lt;/mx:AdvancedDataGrid&gt;<br>
      &lt;/mx:Application&gt;   </p>
  
  <ul>
  <li><p>the data object  in action script
  public class Purchase
  {
  public function Purchase() {</p>
  
  <p>}</p>
  
  <p>private var _id:int = -1;
  private var _category:String = null;
  private var _productName:String = null;<br>
  private var _preferred:Boolean=false;       </p>
  
  <p>public function get id():int {
      return _id;
  }</p>
  
  <p>public function set id(pId:int):void {
      _id = pId;
  }</p>
  
  <p>public function get category():String {
      return _category;
  }</p>
  
  <p>public function set category(pCategory:String):void {
      _category = pCategory;</p>
  
  <pre><code>if ((_category == null) || (_category == "")) {               
      _category = "Default Category";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>public function get name():String {
      return _productName;
  }</p>
  
  <p>public function set name(pName:String):void {
      _productName = pName;</p>
  
  <pre><code>if ((_productName == null) || (_productName == "")) {
      _productName = "default product name";
      category = _productName;
   }
  </code></pre>
  
  <p>}</p>
  
  <p>public function get isPreferred() : Boolean {
      return _preferred;
  }</p>
  
  <p>public function set isPreferred(pPreferred:Boolean) :void {
      _preferred=pPreferred;
  }
  }</p></li>
  </ul></li>
  </ul>