views:

74

answers:

2

This might be an easy one for you DataGrid experts out there. I following an example for adding rows to a DataGrid dynamically from within a row

http://www.switchonthecode.com/tutorials/adding-dynamic-rows-to-flex-datagrid

My tweak that I am trying to acoomlish, is to have a custom itemEditor that is a form with two TextInputs and an OK button. For the life of me I can't get that button to trigger the DataGrid's itemEditEnd event where I have some processing before I call destroyItemEditor. I tried dispatching the event myself directly but got a strange error in DataGrid's updateDisplayList saying editedItemPosition was null (editedItemPosition.rowIndex). Any ideas?

A: 

itemEditEnd will be triggered when you click outside the item editor. If you are dispatching it yourself, you need to set the rowIndex property of the event to the appropriate value before dispatching.

Amarghosh
I actually had the rowIndex (and all other DatGridEvent properties) set but just kept getting that odd error.
A: 

I figured out the "duh" answer. Basically, within the itemEditor get reference to the DataGrid using listData.owner and then set the DataGrid's editedItemPosition and selectedIndex. This way lets the component worry about cleaning up the itemEditor.

var grid:DataGrid = listData.owner as DataGrid;
grid.editedItemPosition = null;
grid.selectedIndex = -1;