[flexcoders] DataGrid cell problem overriding setFocusedCell() method

2005-05-09 Thread bhaq1972
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});
}
   

Re: [flexcoders] DataGrid cell problem overriding setFocusedCell() method

2005-05-09 Thread Jim Laing
On 5/9/05, bhaq1972 [EMAIL PROTECTED] wrote:
 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'm not able to replicate your problem. I ran the code posted and the
focus changed as it should from cell to cell. Can you make sure that
the code you posted is identical to the code you are testing? If so, I
guess we'll have to start comparing versions and setups, etc.

The issue that the code posted *does* display is that the combo box
does actually edit the data provider. This can likely be solved by
overriding the editCell() function so that it actually gets the
correct data from the cellEditor.

Also, what exactly are you trying to accomplish? I may have a solution
that might work for you (but implemented differently), so I'm
interested in the requirements. Also, I'll have to ask my boss to make
sure I can release the code.

Jim


 
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/
 




Re: [flexcoders] DataGrid cell problem overriding setFocusedCell() method

2005-05-09 Thread Jim Laing
On 5/9/05, Jim Laing [EMAIL PROTECTED] wrote:
 I'm not able to replicate your problem. 

AHHH! Spoke too soon again! That's twice in one day ... I can, in
fact, replicate the problem. I did it wrong before 

However, not only can I replicate your problem, I can also fix it
(this is a hack cause I did it quick, but you get the idea): Overload
the disposeEditor() function and make it destroy the dropdown movie
clip. See the code attached.

I'm still interested in what your requirements are cause my solution
might be more general, if it is applicable (the idea of removing the
combobox dropdown comes it ... via MM support).

Jim

function disposeEditor() : Void {
cellEditor.dropdown.removeMovieClip();
cellEditor.mask.removeMovieClip();
super.disposeEditor(); 
}


 
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/