I’m trying to setup a DataGrid that contains a column of combo boxes. The values of the combo boxes are defined by data specific to that row. I cannot get this to work though, I’m asking for a solution to this, either fixing what I have below or a recommendation on a different way.
One of the columns of my DataGrid has an object derived from a ComboBox for an ItemEditor. The itemEditor is set like this:
<mx:DataGridColumn editorDataField="selectedItem" dataField="type" editable="true" >
<mx:itemEditor>
<mx:Component>
<FilterCell:SelectCellBase initialize="set_combo()" grid="{this}"/>
</mx:Component>
</mx:itemEditor>
</mx:DataGridColumn>
So that when the itemEditor is generated (when the user double clicks on the cell) the data is populated.
Then, the SelectCellBase set_combo() function is defined as such:
public function set_combo( ) : void
{
var type : String = grid.dataProvider[grid.selectedIndex]['type'];
if( 'text' == type )
{
this.dataProvider = text;
}
else
{
this.dataProvider = number;
}
}
This implementation isn’t working though because when I try to call grid.selectedIndex this always seems to return -1.
What am I doing wrong, or what better way is there to do this?
Your problem is that when you’re inside of an
<mx:Component>the scope is local, and no longer set to the outside MXML file. So when you have:the “this” you’re referring to is the inline component you’ve defined, not the base MXML component you’re working on. The easy fix is to change it to
the outerDocument variable is automatically set when you’re inside of an
<mx:Component>tag, and can be used to access anything needed from the parent scope.