PDA

View Full Version : DataGrid.selectedItem - reference or copy?


drkstr
09-28-2007, 05:31 AM
**EDIT: Resolved **

I need to be able to modify a property of the selectedItem in the DataGrid and have the property in my data provider update as well (which it should do if selectedItem is a reference to the data provider's item). However, when I update a property of the class by referencing it with DataGrid.selectedItem, it doesn't seem to update my data provider's class property.

Does the DataGrid.selectedItem return a copy of the class instance, or am I just doing something wrong somewhere else in the app?


<mx:DataGrid id="idBoardGrid" width="100%" height="100%"
change="onBoardChange( BoardModel(idBoardGrid.selectedItem) );"
editable="true" rowCount="5"
dataProvider="{myBoardManager.boardCollection}" />

<mx:Button label="Save Selected"
click="onSaveSelectedClicked( BoardModel(idBoardGrid.selectedItem) );" />



private function onSaveSelectedClicked( boardModel:BoardModel ): void {
//myBoardManager.saveBoard(boardModel);
boardModel.dataChanged = false;
for each( var board:BoardModel in myBoardManager.boardCollection ) {
trace('Data Changed? '+board.dataChanged)
}
}


Before I click the button, the 1st (0) item is selected and it's dataChagned property is true. Here is the output of the trace statement:


Data Changed? true
Data Changed? false


The livedocs say the selectedItem is a "A reference to the selected item in the data provider", but this doesn't seem to be the case. Any recommendations on how to get a reference to the original class instance through the data grid?

Thanks for your time!
...aaron

drkstr
09-28-2007, 05:43 AM
Please disregards. The problem was with a typo in my setter. DataGrid.selectedItem does reference the class instance as expected.

Sorry for the wasted post,
...aaron

isdito
03-08-2009, 03:04 AM
I have the same problem, I am taking items of one datagrid and putin to another, but are referencing and not like this... I like a copy.

Thanks and sorry my bad english