After I set the editedItemPosition from the arrow key pressed, I
refresh the dataprovider, because that seemed to make it move the
focus properly.  For the 'selectAll' function, I perform an
itemUpdated on the arraycollection after setting the new item in it,
and then refresh the dataprovider, since I didn't see the new data in
the grid if I didn't.  Is there a better way (i.e. one that works)
that I should do to get the cell to navigate properly with the arrow
keys and the new data to be reflected in the row?

Thanks,

John
--- In flexcoders@yahoogroups.com, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> Are you resetting the dataprovider or some other dataprovider?  I would
> not recommend doing that.
> 
> ________________________________
> 
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
> Behalf Of j_lentzz
> Sent: Tuesday, November 27, 2007 11:32 AM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Losing Focus in DataGrid
> 
> 
> 
> Hi,
> 
> I've got a dataGrid that I want to allow someone to set a value in a
> 'selectAll' column and that value will be passed to all the other
> appropriate columns on that row upon the DataGridEvent.ITEM_EDIT_END.
> I also have a custom keyDownHandler, to allow them to use the arrow
> keys to navigate in the grid. The arrow keys navigate just fine (and
> the focus is correct) for all the columns except for the 'selectAll'
> column. When a value is typed in this column and the arrow keys are
> used, the value is passed to the other columns properly, but the grid
> is getting a CANCELLED edit event and the row is deselected. If I use
> the TAB key to navigate from the 'selectAll' column, the other columns
> are updated and the row stays selected. It seems like I'm missing a
> call of some kind in my keyDownHandler, to allow it to function
> properly. A sample of the code follows. If anyone can tell me what
> I'm doing wrong, I'd greatly appreciate it.
> 
> Thanks,
> John
> override protected function keyDownHandler(event:KeyboardEvent):void {
> var eip:Object = this.editedItemPosition;
> var numColumns:int = this.columns.length;
> var dgc:DataGridColumn;
> var numRows:int = (this.dataProvider as ArrayCollection).length;
> 
> if (event.keyCode == Keyboard.TAB)
> return;
> 
> if (eip != null) {
> switch (event.keyCode) {
> 
> case Keyboard.RIGHT:
> // go one cell over (or to the next visible and non-0 width column),
> // or if at end of line, then go to start of next line
> // if no line exists, then create the new line
> var colFound:Boolean = false;
> while (!colFound) {
> if (eip.columnIndex < numColumns) {
> eip.columnIndex++;
> dgc = this.columns[eip.columnIndex] as DataGridColumn;
> if (dgc != null && dgc.visible && dgc.width > 0 && dgc.editable)
> colFound = true;
> }
> else { // at end of row, so go to start of next row
> if (eip.rowIndex < numRows) {
> eip.rowIndex++;
> eip.columnIndex = -1; // start before row, so next loop can
> increment and check
> }
> else { // end of last row, so add row
> // DO THIS
> }
> }
> }
> // set new values
> this.editedItemPosition = eip;
> this.dataProvider.refresh();
> break;
> 
> 
> SAME FOR OTHER ARROW KEYS...
> }
> }
> 
> private function handleEditEnd(event:DataGridEvent):void {
> trace('dgevent reason: ' + event.reason + ' dataField: ' +
> event.dataField );
> 
> if (event.reason != "CANCELLED" && event.dataField == "selectAll") {
> var tempString:String =
> NumericInEmbedded(event.currentTarget.itemEditorInstance).text;
> trace('tempString: ' + tempString);
> if (tempString != null && tempString != "" && tempString != " ")
> callLater(updateRow, [event,
> Number(NumericInEmbedded(event.currentTarget.itemEditorInstance).text)])
> ;
> }
> }
> 
> private function updateRow(event:DataGridEvent, newData:Number):void {
> trace('updateRow called');
> var dpAC:ArrayCollection = LPA_ItemList.dataProvider;
> var dgCols:Array = LPA_ItemList.dg.columns;
> 
> // set all qty columns to this number
> var obj:Object = dpAC.getItemAt(event.rowIndex);
> if (obj["startDate"] != null)
> obj["startDate"] = newData;
> if (obj["endDate"] != null)
> obj["endDate"] = newData;
> 
> for (var i:int=0; i< dgCols.length; i++) { // go through defined
> cols and set date columns to selectAll value
> if ((dgCols[i] as DataGridColumn).dataField.indexOf("date") == 0) {
> obj[(dgCols[i] as DataGridColumn).dataField] = newData;
> }
> }
> dpAC.setItemAt(obj,event.rowIndex);
> LPA_ItemList.dataProvider = dpAC;
> (LPA_ItemList.dg.dataProvider as ArrayCollection).itemUpdated(obj); 
> // LPA_ItemList.dg.dataProvider.refresh();
> 
> }
>


Reply via email to