2 Replies Latest reply on Aug 16, 2006 11:43 AM by macromichael

    Datagrid itemrenderer listdata Error

    macromichael
      I am having an issue with a datagrid that if you have an itemRenderer, and an itemEditor, the listdata is null. If you only specify either the itemRenderer, or the itemEditor, it works. In the example code below, the first column works, and the second gives a null exception. Perhaps someone with greater insight can share their brilliance on this one.

      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:local="*">

      <mx:Script>
      <![CDATA[
      [Bindable]
      public var initDG:Array = [
      {startdate: new Date('Fri May 5 08:00:00 GMT-0600 1905'),enddate: new Date('Fri May 5 09:00:00 GMT-0600 1905')},
      {startdate: new Date('Fri May 5 08:00:00 GMT-0600 1905'),enddate: new Date('Fri May 5 09:00:00 GMT-0600 1905')} ];
      ]]>
      </mx:Script>
      <mx:Component id="editdt">
      <mx:TextInput preinitialize ="initTA();">
      <mx:Script>
      <![CDATA[

      import mx.data.messages.DataAssociationMessage;
      import mx.controls.dataGridClasses.DataGridListData;
      import flash.events.Event;

      private var datein:Date;

      public function initTA():void {
      addEventListener("dataChange", handleDataChanged);
      }

      public function get newTime ():Date {
      trace("get "+text);
      // validate
      return datein;//textin.text;
      }

      public function handleDataChanged(event:Event):void {
      // Cast listData to DataGridListData.
      var myListData:DataGridListData = DataGridListData(listData);
      var field:String=myListData.dataField;
      // Access information about the data passed to the item renderer.
      if (field == "startdate"){
      datein = event.currentTarget.data.startdate;
      } else {
      datein = event.currentTarget.data.enddate;
      }
      text=df.format(datein);
      }
      ]]>
      </mx:Script>
      <mx:RegExpValidator expression="^(\d|1[0-2]):[0-5]\d [apAP][mM]$"/>
      <mx:DateFormatter id="df" formatString="L:NN A"/>
      </mx:TextInput>

      </mx:Component>
      <mx:DataGrid id="myGrid" dataProvider="{initDG}" variableRowHeight="true" editable="true">
      <mx:columns>
      <mx:DataGridColumn dataField="enddate" itemEditor="{editdt}" editorDataField="newTime"/>
      <mx:DataGridColumn dataField="startdate" itemEditor="{editdt}" editorDataField="newTime">
      <mx:itemRenderer>
      <mx:Component>
      <mx:VBox clipContent="false">
      <mx:DateFormatter id="df" formatString="L:NN A"/>
      <mx:Text width="100" text="{df.format(data.startdate)}"/>
      </mx:VBox>
      </mx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>
      </mx:columns>
      </mx:DataGrid>
      </mx:Application>


      Thanks
      Michael Hunter -
      FriendlyTek