0 Replies Latest reply on Oct 10, 2007 2:53 AM by

    DataGrid Custom ItemEditor Error

      My first ever post in this forum!
      I use a datagrid with custom item editor of type numericalStepper
      I also add an event (CollectionEvent.COLLECTION_CHANGE) on the data provider, to add a new row when user enters something on the last row of the datagrid
      Using either one of them does not produce the error. When the user clicks "ENTER" key on any custom item editor on the last row, i get the following error:

      TypeError: Error #1009: 無法存取 Null 物件參考的屬性或方法。
      at mx.controls::DataGrid/private::findNextEnterItemRenderer()
      at mx.controls::DataGrid/private::editorKeyDownHandler()
      at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.core::UIComponent/dispatchEvent()
      at mx.controls::NumericStepper/private::inputField_keyDownHandler()
      at [keyboardEvent]

      My source code is quite long, so I copy the relevant code only

      dgc2.itemEditor = new ClassFactory(NumericStepper);
      dgc2.editorDataField = "value";

      emptyXMLListCollection.addEventListener(CollectionEvent.COLLECTION_CHANGE, emptyXMLListCollectionChangerHandler);

      private function emptyXMLListCollectionChangerHandler(event:CollectionEvent):void {

      var node:XML = emptyXML.results[emptyXML.results.length()-1];
      var isRowEmpty:Boolean = true;

      for each (var xml:XML in node.children()) {
      if (xml.toString() != "") {
      isRowEmpty = false;

      if (isRowEmpty == false) {

      private function appendNewRow():void {

      var newNode:XMLNode = new XMLNode(XMLNodeType.ELEMENT_NODE, "results");
      var childNode:XMLNode = null;

      for each (var dgc:DataGridColumn in columns) {

      childNode = new XMLNode(XMLNodeType.ELEMENT_NODE, dgc.dataField);
      childNode.appendChild(new XMLNode(XMLNodeType.TEXT_NODE, ""));



      emptyXMLListCollection = new XMLListCollection(emptyXML.results);
      emptyXMLListCollection.addEventListener(CollectionEvent.COLLECTION_CHANGE, emptyXMLListCollectionChangerHandler);
      dataProvider = emptyXMLListCollection;

      I have completed the following test:
      1. Do not use custom Item Editor --> no error
      2. Do not call the function "appendNewRow", which means that data provider is not changed when user presses "ENTER" key on last row of datagrid --> no error
      3. After looking into datagrid.as in SDK, i found that the property "lastEditedItemPosition" is null in the method "findNextEnterItemRenderer". I think this is caused by the "appendNewRow()" function, which changes the data provider