Hi
I have created a DataGrid which has an overriding setFocusedCell()
method (copy and pasted from DataGrid.as), with the following
changes.
1) I had to remove a reference to 'roundUp' as the compiler didnt
like it.
2) I want my cellEditor to be a ComboBox rather than a TextInput. So
I replaced the following line
cellEditor = listContent.createClassObject
(mx.controls.TextInput, editorName, EDITORDEPTH, {styleName:col,
listOwner:this});
with
var dp = [s1, s2, s3, s4];
cellEditor = listContent.createClassObject
(mx.controls.ComboBox, editorName, EDITORDEPTH, {styleName:col,
listOwner:this, dataProvider:dp, editable:true});
The problem i have is, the combobox dropdown doesnt close, when you
click elsewhere on the Datagrid.
There is no problem if combobox.editable = false (initial parameter
passed to craeteClassObject)
I appreciate any help. Code is below.
BTW. I dont want to use a custom cell renderer. This is only a
simple example to highlight my problem.
Regards
bod(bhaq1972)
test.mxml
-
?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.macromedia.com/2003/mxml;
xmlns:nx=* backgroundColor=#C0DCC2
mx:Script
![CDATA[
var dp = [{ one:one, two:two, three:three },
{ one:four,
two:five, three:six },
{ one:seven,
two:eight, three:nine },
{ one:ten,
two:eleven, three:twelve },
{ one:thirteen,
two:fourteen, three:fifteen }];
]]
/mx:Script
mx:TextArea width=200 height=100 text=Select a cell from the
datagrid. Then click the arrow to get the dropdown, and then mouse
focus elsewhere /
nx:DataGridCombo editable=true id=dg dataProvider={ dp }
nx:columns
mx:Array
mx:DataGridColumn columnName=one/
mx:DataGridColumn columnName=two /
mx:DataGridColumn columnName=three/
/mx:Array
/nx:columns
/nx:DataGridCombo
/mx:Application
DataGridCombo
-
?xml version=1.0 encoding=utf-8?
mx:DataGrid xmlns:mx=http://www.macromedia.com/2003/mxml;
mx:Script
![CDATA[
import mx.controls.gridclasses.DataGridColumn;
import mx.controls.gridclasses.DataGridRow;
import mx.core.UIObject;
function setFocusedCell(coord:Object, broadCast) : Void
{
if (!enabled || !editable) return;
// allow setting of undefined to dispose cell editor
if (coord==undefined cellEditor!=undefined) {
disposeEditor();
return;
}
// get all details for the cell to be focused.
var index : Number = coord.itemIndex;
var colIdx : Number = coord.columnIndex;
if (index==undefined) index = 0;
if (colIdx==undefined) colIdx = 0;
var colName :String = __columns[colIdx].columnName;
// scroll so the cell is in view
if (__vPositionindex) {
setVPosition(index);
} else {
//var delt = index-__vPosition-__rowCount+roundUp+1;
var delt = index-__vPosition-__rowCount+1;
if (delt0) {
setVPosition(__vPosition+delt);
}
}
// get the actual references for the column, row,
and cell
var col : DataGridColumn = __columns[colIdx];
var row : DataGridRow = rows[index-__vPosition];
var cell = row.cells[colIdx];
// scroll so the cell is in view (cont'd)
if (cell._x__hPosition+displayWidth ||
cell._x__hPosition) {
setHPosition(cell._x);
}
// try to get the right data for editing
var editText = __dataProvider.getEditingData(index,
colName);
if (editText==undefined)
editText = __dataProvider.getItemAt(index)
[colName];
if (editText==undefined)
editText= ;
// isCellEditor is part of the cellRenderer
interface. It allows the cell itself to do the editing
if (cell.isCellEditor!=true) {
// if this isn't implemented, use an input
control as editor
if (cellEditor==undefined) {
//cellEditor = listContent.createClassObject(mx.controls.TextInput,
editorName, EDITORDEPTH, {styleName:col, listOwner:this});
var dp = [truckmount, pda, rf, mobile];
cellEditor = listContent.createClassObject(mx.controls.ComboBox,
editorName, EDITORDEPTH, {styleName:col, listOwner:this,
dataProvider:dp, editable:true});
}