0 Replies Latest reply on Sep 7, 2011 9:23 AM by snes2078

    Datagrid colum item renderer HELP!!!!!

    snes2078

      Hi,

       

       

      I have the below datagrid, and I have to populate one of the column with three different images, a cricle an squeare and a triangle. I've been sucessful adding dinamically the differents itemrenderers. For the triangle one it has been a really pain in the *** tying to draw the triangle, but finally i figured it out, and I can draw it, but I cant set the result triangle in the middle of the column, I dont know if it's a Sprite. But I've tried with a button and it sets in th emiddle of the column, so it has to be because the sprite or something i'm doing work in some of the classes. Please HELP!!! I really appreciate your help and advice I'm newbie at Flex.

       

      Thanks in advance!!!

       

       

       

      <s:HGroup y="200" left="22" right="22">

           <s:Group width="100%">

                <mx:DataGrid id="dgDatosMapa" width="357" height="108" visible="true" dataProvider="{arrDatos}" rowHeight="40">

                     <mx:columns>

                     <mx:DataGridColumn headerText="Símbolo" dataField="simbolo" textAlign="center" width="80" />

                     <mx:DataGridColumn headerText="Tamaño" dataField="size" textAlign="center" visible="false" />

                     <mx:DataGridColumn headerText="Intervalo" dataField="intervalo" textAlign="center" width="80"/>

                     <mx:DataGridColumn headerText="Rótulo" dataField="rotulo" textAlign="center" width="80"/>

                     </mx:columns>

                </mx:DataGrid>

           </s:Group>

      </s:HGroup>

       

       

      var col:DataGridColumn = dgDatosMapa.columns[0];

      col.itemRenderer = new ClassFactory(triangle);

       

       

      package widgets

      {

      import flash.accessibility.AccessibilityProperties;

      import flash.display.DisplayObject;

      import flash.display.DisplayObjectContainer;

      import flash.display.Graphics;

      import flash.display.LoaderInfo;

      import flash.display.Sprite;

      import flash.display.Stage;

      import flash.events.Event;

      import flash.geom.Point;

      import flash.geom.Rectangle;

      import flash.geom.Transform;

       

      import mx.containers.Canvas;

      import mx.containers.HBox;

      import mx.controls.List;

      import mx.controls.listClasses.IListItemRenderer;

      import mx.controls.listClasses.ListItemRenderer;

      import mx.core.UIComponent;

      import mx.managers.ISystemManager;

       

      import spark.components.Group;

      import spark.primitives.Graphic;

      import spark.primitives.Line;

       

      import widgets.CustomImportLayers.ImportLayers;

       

       

      public class triangle  extends UIComponent implements IListItemRenderer

      {

      private var _objData:Object;

      private var sprite:Sprite;

       

      public function triangle()

      {

      super();

      height=20;

      width=16; 

      }

       

      override protected function createChildren():void

      {

      super.createChildren();

       

      }

       

      override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void

      {

      super.updateDisplayList(unscaledWidth,unscaledHeight);

      }

       

      public function drawTriangle(datos:Object):void

      {

      _objData = datos;

      sprite = new Sprite();

      var triangleHeight:int = (_objData.size/4);

      var uic:UIComponent = new UIComponent();

      sprite.graphics.lineStyle(1,int(0x000000),1);

      sprite.graphics.beginFill(_objData.simbolo);

      sprite.graphics.moveTo((triangleHeight/2)+2, 3);

      sprite.graphics.lineTo(triangleHeight+2, (triangleHeight+1));

      sprite.graphics.lineTo(2, triangleHeight+1);

      sprite.graphics.lineTo((triangleHeight/2)+2, 3);

      sprite.graphics.endFill();

      uic.addChild(sprite);

      this.addChild(uic);

      }

       

       

      override protected function commitProperties() : void

      {

      super.commitProperties();

      }

       

       

      public function set data(value:Object):void

      {

      _objData = value;

       

      }

       

       

      public function get data():Object

      {

      return _objData;

      }

       

      }

      }

       

      package widgets

      {

      import mx.containers.HBox;

      import mx.containers.VBox;

      import mx.controls.Button;

       

      import spark.components.Group;

       

      import widgets.GenMapasTematicos.triangle;

       

      public class tri  extends HBox

      {

      private var trian:triangle;

      private var _objData:Object;

       

      public function tri()

      {

      super();

      this.width=80;

      this.setStyle("horizontalAlign", "center");

      this.setStyle("verticalAlign", "top");

      }

       

      override protected function createChildren():void

      {

      var b:Group = new Group();

      b.percentWidth=100;

      this.addChild(b);

      trian = new triangle();

      b.addElement(trian);

      }

       

      override protected function commitProperties() : void

      {

      super.commitProperties();

       

      trian.drawTriangle(_objData);

      }

       

      override public function set data(value:Object):void

      {

      _objData = value;

      super.invalidateDisplayList();

      }

       

       

      override public function get data():Object

      {

      return _objData;

      }

      }

      }