Tracy, this was posted on the Adobe forums as well with code and is being 
handled over there.

Alex Harui
Flex SDK Developer
Adobe Systems Inc.<http://www.adobe.com/>
Blog: http://blogs.adobe.com/aharui

From: [email protected] [mailto:[email protected]] On Behalf 
Of Tracy Spratt
Sent: Thursday, April 23, 2009 10:40 AM
To: [email protected]
Subject: RE: [flexcoders] DataGrid combobox erasing items from it's list




So the scenario is:

 1.  user clicks cell, CB editor appears
 2.  user clicks away somewhere, without selecting anything
 3.  ComboBox closes
 4.  an empty string is stored in the dataProvider

Yes?  Is the change event and handler firing in this case?

If so, then I think you need to make the renderer set the ComboBox's 
selectedIndex to display the current value.  Thus however the change event was 
caused, the correct value would be put back in the property.

I think you would want this behavior anyway.  Note you can't directly set 
selectedItem, but must loop over the dataProvider comparing property values, 
then using the loop index to set the selectedIndex.

Tracy Spratt,
Lariat Services, development services available
________________________________
From: [email protected] [mailto:[email protected]] On Behalf 
Of netdeep
Sent: Thursday, April 23, 2009 9:57 AM
To: [email protected]
Subject: [flexcoders] DataGrid combobox erasing items from it's list






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