2 Replies Latest reply on May 6, 2008 12:22 AM by Dema_In_Russia

    Object in Datagrid


      I have following object (Class).

      public class CheckCanvas extends Canvas
      var a:Check;
      var b:Check;
      public function CheckCanvas()
      var f:UIComponent = this.parent as UIComponent;
      this.width = 120;
      this.height = 50;
      var a0:Check = new Check("docSel",false);
      a= a0;
      a.y = 5;
      a.x= 30;
      var b0:Check = new Check("docUnsel",false);
      b = b0;
      b.x = 80;
      b.y = 5;

      And I call this Object from Application throw datagrid
      <mx:DataGrid id="dataIn" dataProvider="{sourceDataIn}" >
      <mx:DataGridColumn width="132" dataField="word" itemRenderer="source.CheckCanvas"/>

      How can I get param from field "datafield" (in in the present state of affairs - "word") in my class (CheckCanvas) ???

      Please, help me.
        • 1. Re: Object in Datagrid
          peterskeeter Level 1
          In an itemrenderer you need to use this function

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


          to access the datagrid variable being rendered in your itemrenderer.
          Hence value will take on the object that gets passed into your itemrenderer.

          here is an example of me using this function in an image itemrenderer a little ago..

          override public function set data(value:Object):void {
          if (value != null)
          var r:Label = new Label();
          r.text = value.mylabel;
          var s:Image = new Image();

          In this case the datagrids datasource was this arraycollection.

          var mydata:ArrayCollection=new ArrayCollection([{mylabel:'A', path:'a.jpg'}, {mylabel:'B', path:'b.jpg'},{mylabel:'C', path:'c.jpg'},{mylabel:'D', path:'c.jpg'},{mylabel:'E', path:'c.jpg'},{mylabel:'F', path:'c.jpg'}]);

          so you can see how the araycollection has the "mylabel" field and how that is referenced in the itemrenderer..

          hope this helps..
          • 2. Re: Object in Datagrid
            Dema_In_Russia Level 1
            Thank, peterskeeter...
            all working...