Still no response on my CellRenderer question - probably lost in the
Flashcoders digest fiasco. :)
Does anyone have ANY experience with CellRenderer w/a ComboBox and a
changing DataGrid? I have made progress updating the ComboBoxeds in the
cell when dataprovider changes, and am 95% done, but still one last bug
I cannot seem to figure out.
I have a comboBox, which changes the data in a datagrid. Works fine.
The datagrid has comboBoxes in one of the collums added with the
CellRenderer API. Works fine - when the datagrid changes, the
comboBoxes change their selectedIndex accordingly. However, once the
dataGrid changes, the comboBoxes stop working - you cannot select a
different index in the combox - it keeps defaultinng to the current
selectedIndex when to try and select a different index. So I made an
example file which duplicates the problem - here is the code in the .fla
and the CellRenderer class for the comboBox:
//code in the .fla:
this.createClassObject(mx.controls.DataGrid, "myGrid_dg", 1);
myDP = [{name:"Jason", access:{label:"Medium", data:1}},
{name:"Jerry", access:{label:"Medium", data:1}},
{name:"Jenny", access:{label:"Medium", data:1}}]
myGrid_dg.dataProvider = myDP;
myGrid_dg.setSize(430,200);
myGrid_dg.move(40,40);
myGrid_dg.getColumnAt(1).cellRenderer = "ComboBoxCell";
choose_cbx.dataProvider = [{label:"4 people High"},
{label:"3 people Medium"},
{label:"2 people Low"}]
var cbListener:Object = new Object();
cbListener.change = function (evt_obj:Object)
{
//this is kludgy, I do it differently in my real app,
//but just for example sake:
if(evt_obj.target.selectedItem.label=="2 people Low"){
thisDP = [{name:"Larry", access:"Low", data:0},
{name:"Louis", access:"Low", data:0}];
}else if(evt_obj.target.selectedItem.label=="3 people Medium"){
thisDP = [{name:"Stan", access:"Medium", data:1},
{name:"Susan", access:"Medium",
data:1},
{name:"Sherry", access:"Medium",
data:1}];
}else{
thisDP = [{name:"Allison", access:"High", data:2},
{name:"Al", access:"High", data:2},
{name:"Ana", access:"High", data:2},
{name:"Anderson", access:"High",
data:2}];
}
myGrid_dg.dataProvider = thisDP;
}
choose_cbx.addEventListener("change", cbListener);
//ComboBoxCell.as file:
import mx.controls.ComboBox;
class com.boa.experiments.ComboBoxCell extends mx.core.UIComponent
{
var getDataLabel:Function;
var getCellIndex:Function;
private var owner; // The row that contains this cell.
private var listOwner; // The List, data grid or tree containing
this cell.
private var cb; //the checkbox instance
public function ComboBoxCell()
{
}
public function createChildren():Void
{
cb = this.createClassObject(mx.controls.ComboBox, "cb",
1);
cb.addEventListener("change", this);
cb.dataProvider = [{label:"Low"},
{label:"Medium"},
{label:"High"}]
cb.setSize(100, 25);
cb._x = 5; cb._y = 0;
}
public function setValue(str:String, item:Object, sel:Boolean):Void
{
//item is the dataprovider field i.e. access
cb._visible = (item!=undefined);
cb.selectedIndex = item.data;
}
function change():Void
{
//changes one field of the data provider.
var thisField:Object = getDataLabel()
listOwner.dataProvider.editField(getCellIndex().itemIndex,
thisField.data, cb.selectedIndex);
}
};
Any ideas? I can get the comboBoxes to automatically change their
selectedIndex according to the new dataProvider, OR, I can change the
code to allow the comboBoxes to funciton and allow the user to select an
index in the comboBox, but not both! Maddening for sure.
Jason Merrill
Bank of America
Global Technology & Operations, Learning & Leadership Development
eTools & Multimedia Team
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com