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 (__vPosition>index) {
setVPosition(index);
} else {
//var delt = index-__vPosition-__rowCount+roundUp+1;
var delt = index-__vPosition-__rowCount+1;
if (delt>0) {
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});
}
// give it the right size, look and placement
cellEditor.backgroundColor = 0xffffff;
cellEditor._visible = true;
cellEditor.setSize(col.__width,
__rowHeight+2);
cellEditor._x = cell._x-1;
cellEditor.text = editText;
// set up a mask for our cute little wipe
effect for the editor
editorMask = listContent.attachMovie
("BoundingBox", "editorMask", 60001, {_alpha:0});
cellEditor.setMask(editorMask);
editorMask._width = cellEditor.width;
editorMask._height = cellEditor.height;
editorMask._y = cellEditor._y = row._y-1;
editorMask._x = cellEditor._x-
editorMask._width;
// start the wipe - see onTweenUpdate/end
for the results
editTween = new mx.effects.Tween(this,
cellEditor._x-editorMask._width, cellEditor._x, 150);
// Block all layout, responses from web
service, and other background
// processing until the tween finishes
executing.
UIObject.suspendBackgroundProcessing();
} else {
// if the cell is a cellEditor, we'll use it
cellEditor = cell;
cellEditor.setValue(editText,
__dataProvider.getItemAt(index));
}
// set focus to the cellEditor. It is now
essentially in control of input until the Mouse
// is clicked away, or ESC/ENTER/TAB are hit
var fM = getFocusManager();
fM.setFocus(cellEditor);
fM.defaultPushButtonEnabled = false;
if (cell.isCellEditor!=true) {
// only for text input - tends to scroll
after focused, so we scroll it back
cellEditor.hPosition = 0;
cellEditor.redraw(); // This
makes sure that the text is in the label TextField, so setSelection
will always work.
Selection.setSelection(0, cellEditor.length);
}
// store the value
__focusedCell = coord;
// tricky business. Steal the focusManager's method
of catching tabs,
// and replace it with our own, which will do *our*
bidding <nefarious laughter>.
if (__tabHandlerCache == undefined)
{
__tabHandlerCache = fM.tabHandler;
fM.tabHandler = tabHandler;
}
// give the fM a reference to us (our tabHandler
needs it)
fM.activeGrid = this;
// listen for keyStrokes on the cellEditor (which
lets the grid supervise for ESC/ENTER)
cellEditor.addEventListener("keyDown",
this.editorKeyDown);
// broadcast the focus event
if (broadCast) {
dispatchEvent({type:"cellFocusIn",
itemIndex: index, columnIndex: colIdx});
}
}
]]>
</mx:Script>
</mx:DataGrid>
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/