tags:

views:

559

answers:

2

I have a DataGrid which contains a DataGridColumn with a textinput and DataGridColumn with a Button. The DataGrid is bound to some XML which displays values in the text box. When the button for a row is clicked I need to get the value out of the text box and save it into the relevant XML node.

My solution was just to pass the id of the row to the button click event then loop over the rows until I find the id then just grab the text box value. Simple.

However the only advice I can find on looping over the rows is via the underlying dataProvider, which is nonsense as the two aren't the same thing.

Is this even possible? or is there a better way?
NOTE I would prefer not re-writing the markup, unless I have to.
Thanks

+1  A: 

listData.rowIndex from the itemRenderer returns the current row index. You can read it from the click handler as:

private function clickHandler(event:MouseEvent):void
{
  var listData:BaseListData = IDropInListItemRenderer(event.target).listData;
  var clickedRowIndex:Number = listData.rowIndex;
}
Amarghosh
make sure that the event.target actually implements IDropInListItemRenderer; for example, many containers do not implement this, while many components do.
Luis B
i believe he has a `Button` as the itemRenderer
Amarghosh
+2  A: 

You are probably using an itemRenderer for your DataGridColumn to show the textBox (aka, TextInput component). I suggest that you dispatch a custom event out of the TextInput itemRenderer when you have a TextInput.dataChange event (or some other TextInput.Event that suits when you are ready to save the value).
http://livedocs.adobe.com/flex/3/langref/mx/controls/TextInput.html

Please remember that you need to bubble this event handling outside of the itemRenderer (e.g., the DataGrid) -- itemRenderers don't handle events well.
Also, one reason that a button to save your TextInput value is not a good idea, is because they are both itemRenderers, and it is hard to communicate between itemRenderers -- it is hard because Adobe deems it unclean code.
http://www.adobe.com/devnet/flex/articles/itemrenderers%5Fpt1.html

Also, this is another solution that changes the dataProvider for a ComboBox (in your case, it's a TextInput instead of ComboBox):
http://www.switchonthecode.com/tutorials/simple-datagrid-item-editor-in-flex

Luis B
Some good advice thanks i'll investigate
Adam Naylor