I am trying to put a combobox inside a datagrid. I managed to get it this far:
http://img8.imageshack.us/img8/8325/captureyma.jpg
Shown in that image is my combobox, populated with data. The problem is that if I set the selectedIndex of the combobox to whatever value is in the corresponding cell, the user can no longer change the value of the combobox. What I mean is, you click on the combobox, a list appears to select from, but you can not select any item in that list.
Here’s my code:
package
{
import fl.controls.listClasses.ICellRenderer;
import fl.controls.listClasses.ListData;
import fl.core.InvalidationType;
import fl.controls.ComboBox;
import fl.controls.DataGrid;
import fl.data.DataProvider;
import flash.events.Event;
import flash.utils.getDefinitionByName;
import flash.display.DisplayObject;
public class ComboBoxCell extends ComboBox implements ICellRenderer
{
protected var _data:Object;
protected var _listData:ListData;
protected var _selected:Boolean;
public function ComboBoxCell()
{
super();
addEventListener( Event.CHANGE, handleEvent );
var hr:Number = 12;
var hour:String;
var min:Number = 0;
var minute:String;
var tt:String = "am";
for (var i:Number = 0; i < 96; i++)
{
hour = String(hr);
/*if (hr < 10)
hour = "0" + hour;*/
minute = String(min);
if (min < 10)
minute = "0" + minute;
addItem({label: hour + ":" + minute + tt, data: hour + ":" + minute + tt});
min+=15;
if (min >= 60)
{
hr++;
min = 0;
if (hr == 12)
{
if (tt == "am")
tt = "pm";
else
tt = "am";
}
else if (hr == 13)
hr = 1;
}
}
}
private function handleEvent( event:Event ) : void {
//data.selectedIndex = selectedIndex;
data.selected = selectedIndex;
_data = getItemAt(selectedIndex);
listData.owner.dispatchEvent( new Event( Event.CHANGE ) );
}
public function get data() : Object {
return _data;
}
public function set data(value:Object) : void {
// value: The record object added
// - {column1: value1, column2: value2, ..}
for (var i:Number=0; i<length; i++)
{
if (getItemAt(i).data == value["starttime"])
{
selectedIndex = i;
break;
}
}
_data = {label:value["starttime"], data:value["starttime"]}; //value;
}
public function get listData() : ListData {
return _listData;
}
public function set listData(value:ListData) : void {
_listData = value;
invalidate(InvalidationType.DATA);
invalidate(InvalidationType.STATE);
}
public function get selected() : Boolean {
return _selected;
}
public function set selected(value:Boolean) : void {
_selected = value;
invalidate(InvalidationType.STATE);
}
public function setMouseState(state:String) : void {
}
}
}
This is what I believe is the problem. If I set the selectedIndex, the user can’t select any item from the combobox.
public function set data(value:Object) : void {
// value: The record object added
// - {column1: value1, column2: value2, ..}
for (var i:Number=0; i<length; i++)
{
if (getItemAt(i).data == value["starttime"])
{
selectedIndex = i;
break;
}
}
_data = {label:value["starttime"], data:value["starttime"]}; //value;
}