Looks like you could just override set data(value:Object):void in your
mxmlcomponents.TypeComboBoxRenderer class. That override could looks
something like:
override public function set data(value:Object):void
{
if(value != null)
{
super.data = value;
this.text = value.name;
}
}
This should get you close...
hth
Scott
Scott Melby
Founder, Fast Lane Software LLC
http://www.fastlanesw.com
johnskidgel wrote:
Hi All,
I'm using a comboBox as an itemRenderer in a DataGrid's
DataGridColumn. I'm also using the same itemRenderer as the editor and
have set the rendererIsEditor to true.
My problem is in initializing the comboBox to use the original value
specified by the dataProvider and not the first option in the
combobox. (which may or may not be the actual value) I've pasted a
simple example to see if someone can point out what I'm doing wrong.
I've found cellRenderers (for the AS3 UI components in Flash) and
itemRenderers in Flex to be a tricky subject. Flex has been easier to
implement overall though.
I'd like to see more examples of these using all the various types of
standard components (and comboboxes specifically :-) in the next
version of the documentation.
The main application file (which i based on a code sample from the docs):
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var myDP:ArrayCollection = new ArrayCollection([
{Name: 'Item 1', Number: '10000', Type: 'alpha' },
{Name: 'Item 2', Number: '10000', Type: 'beta' }
]);
]]>
</mx:Script>
<mx:DataGrid id="myGrid"
dataProvider="{myDP}"
editable="true"
width="100%" >
<mx:columns>
<mx:DataGridColumn dataField="Name"/>
<mx:DataGridColumn dataField="Number"/>
<mx:DataGridColumn dataField="Type"
headerText="Type"
rendererIsEditor="true"
itemRenderer="mxmlcomponents.TypeComboBoxRenderer"
editorDataField="newType"
editorXOffset="5"
editorYOffset="0">
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:WindowedApplication>
The mxml component I'm using:
<?xml version="1.0" encoding="utf-8"?>
<!-- mxmlcomponents/TypeComboBoxRenderer.mxml -->
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Script>
<![CDATA[
// Define a property for returning the new value to the cell.
[Bindable]
public var newType:String;
]]>
</mx:Script>
<mx:ComboBox id="contactCombo"
change="newType=contactCombo.selectedLabel;">
<mx:ArrayCollection>
<mx:String>alpha</mx:String>
<mx:String>beta</mx:String>
</mx:ArrayCollection>
</mx:ComboBox>
</mx:VBox>