Get or Set Cell Values in a Datagrid progmatically

Craig Mc picture Craig Mc · Oct 8, 2010 · Viewed 9.7k times · Source

In Flex 4 using a pre populated data grid, how can I get or set specific values programatically, IE I wont be using selectedItems etc.

How do I reference the value of a cell in row 4 colum 6 for example.

Please and thank you in advance for your help.

Craig

Answer

Amarghosh picture Amarghosh · Oct 8, 2010

Cast the dataProvider of the DataGrid to ListCollectionView and use its getItemAt method.

ListCollectionView(dataGrid.dataProvider).getItemAt(requiredRow).appropriateProperty = newValue;

Update: In case the column name is dynamic, you can fetch it using something like:

var data_field:String = dgViewPreview.columns[6].dataField; //for 6th column
ListCollectionView(dataGrid.dataProvider).getItemAt(requiredRow)[data_field] = newValue;