Hi,

Your code looks fine.  But, I believe that you need to handle the
itemEditEnd event, for the DataGrid:

<mx:DataGrid itemEditEnd="onItemEditEnd(event);"/>

  Something like this:

private function onItemEditEnd(event:DataGridEvent):void
{
      // Check the reason for the event.
      if (event.reason == DataGridEventReason.CANCELLED)
      {
           // Do not update cell.
           return;
      }

      // Get the new data value from the editor.
      var newData:String =
ComboBox(event.currentTarget.itemEditorInstance).selectedLabel;

      // Determine if the new value is an empty String.
      if(newData == "")
      {
           // Prevent the user from removing focus,   and leave the cell
editor open.
           event.preventDefault();
           return;
      }
}

-TH

--- In [email protected], "netdeep" <deep...@...> wrote:
>
>
> I have a DataGrid that is linked to an array of custom data objects
which I call a seriesList. You are supposed to be able to choose the
name of each series via a combobox in the datagrid. It works fine except
when the user selects the combobox and then clicks somewhere else in the
interface, which closes the combobox and erases whichever item is
previously selected!
>
>
> <!-- Definition in application -->
> <!-- axis.seriesList is and ArrayCollection of actionscript objects
called SeriesObjects which have a var name:String variable -->
> <mx:DataGrid id="seriesTable" color="black" fontSize="9"
rowHeight="30" editable="true" resizeEffect="slow"
rollOverColor="#CCCCCC"
> selectionColor="#999999" dataProvider="{axis.seriesList}" width="100%"
> rowCount="{axis.seriesList.length > 2 ? axis.seriesList.length : 2}" >
> <mx:columns>
> <mx:DataGridColumn dataField="name" headerText="Name" width="280"
headerStyleName="centered" id="nameColumn"
> rendererIsEditor="true" editorDataField="result"
itemRenderer="renderer.SeriesBoxRenderer"/>
> </mx:columns>
> </mx:DataGrid>
>
>
> <!-- SeriesBoxRenderer -->
> <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml";
creationComplete="init()" horizontalAlign="center">
> <mx:Script>
> <![CDATA[
> import mx.collections.ArrayCollection;
> // Define a property for returning the new value to the cell.
> public var result:String="";
>
> [Bindable]
> private var dpValue:ArrayCollection;
>
> private function init():void {
> // list of possible names to choose from for this series
> dpValue = mx.core.Application.application.seriesArray;
> }
>
> // Override the set method for the data property.
> override public function set data(value:Object):void {
> if (dpValue == null) init();
> super.data = value;
> if (value != null) {
> var currentValue:String = value.name;
> var len:int = dpValue.length;
> for (var i:int = 0; i < len; i++) {
> if (dpValue[i].name == currentValue) {
> editor.selectedIndex = i;
> return;
> }
> }
> }
> editor.selectedIndex = 0; }
>
> public function onChange():void {
> var index:int = editor.selectedIndex;
> result = dpValue[index].name;
> data.name = dpValue[index].name;
> }
>
> ]]>
> </mx:Script>
> <mx:ComboBox id="editor" textAlign="left" labelField="name"
dataProvider="{dpValue}" change="onChange()"/>
> </mx:VBox>
>


Reply via email to