PDA

View Full Version : How do I get contents of a data grid?


handycam
08-07-2007, 05:01 PM
I've got two data grids. Elements can be dragged from one to the other. The first grid is populated by a binding to a data provider, an XMLList The second grid has not data provider, as it's empty to start.

At some point, I need to get the contents of the second grid, so that I can use the data elsewhere.

What property am I looking for of the second grid?


<mx:HBox width="100%" height="100%">
<mx:DataGrid id="chooseList" dataProvider="{_choices}" width="100%" height="100%" wordWrap="true" variableRowHeight="true" dragEnabled="true" dropEnabled="true" dragMoveEnabled="true">
<mx:columns>
<mx:DataGridColumn dataField="@ln1" headerText="{_prompt}"/>
</mx:columns>
</mx:DataGrid>

<mx:DataGrid id="choiceList" width="100%" height="100%" wordWrap="true" variableRowHeight="true" editable="true" dropEnabled="true" dragEnabled="true" dragMoveEnabled="true">
<mx:columns>
<mx:DataGridColumn dataField="@qty" headerText="Quantity" width="30"/>
<mx:DataGridColumn dataField="@units" headerText="" width="40"/>
<mx:DataGridColumn dataField="@ln2" headerText=""/>
</mx:columns>
</mx:DataGrid>
</mx:HBox>

dr_zeus
08-07-2007, 06:01 PM
Doesn't dataProvider work? It may be null until you drag something into the DataGrid.

handycam
08-07-2007, 08:10 PM
Doesn't dataProvider work? It may be null until you drag something into the DataGrid.

Yeah. I wound up creating a new, empty ArrayCollection and set that to be the dataProvider for that second grid.


[Bindable]
public var _chosenItems : ArrayCollection = new ArrayCollection();


and

<mx:DataGrid id="choiceList" dataProvider="{_chosenItems}" width="100%" height="100%" wordWrap="true" variableRowHeight="true" editable="true" dropEnabled="true" dragEnabled="true" dragMoveEnabled="true" dragDrop="doDragDrop(event);">
<mx:columns>
<mx:DataGridColumn dataField="@qty" headerText="Quantity" width="70" itemEditor="myComponents.NSEditor" editorDataField="newTotal"/>
<mx:DataGridColumn dataField="@units" headerText="" width="40"/>
<mx:DataGridColumn dataField="@ln2" headerText=""/>
</mx:columns>
</mx:DataGrid>


Then I can use choiceList.dataProvider

Thanks.