views:

18

answers:

1

Hi,

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

+1  A: 

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;
Amarghosh
Firstly thankk you so much for taking the time to answer:Ok that gets me the row, how do I get the specific column
Craig Mc
I have 30 values in a single row I really only want to update only one specific item.
Craig Mc
The scenario is when a user edits an item in my datagrid, I need to update a series of other values in the datagrid which in turn are running totals of certain othr vlaues of the grid.
Craig Mc
would this work: ListCollectionView(dataGrid.dataProvider).getItemAt(requiredColumn,requiredRow).appropriateProperty = newValue; And what is the appropriateProperty for the value of a cell.I have not being able to find any decent documentation on working with cells beyond selectedItem. Which does not apply to anything Im trying to do?
Craig Mc
@Craig it depends on what value you show in that particular column - that's why I used the term `appropriateProperty` - what's the `dataField` of the required DataGridColumn?
Amarghosh
Well the grid in question is more of a pivot, that I build to an indeterminable size.I dont want to change the data for the entire column I just want to evaluate each indvidual CELL and then change its value as needed.
Craig Mc
@Craig Can you post the relevant code - of the DataGrid and desired column's?
Amarghosh
So imagine that if user changes the cell in Row 6 Column4 I might potentially Update the cell correspoding to Row 1 column 4, Row 2 Column 4
Craig Mc
MXML - http://pastebin.com/e3mSxd1imydata.xml - http://pastebin.com/RV0D6Y5jYou will see that I build the structure up depending on my data which can vary considerably depending on some external factor and data on the day.But the intent is if a user edits one value a number of other values need to be updated.
Craig Mc
@Craig The way it works is like this: there'll be a data provider with many objects in it. Each object will have a set of properties. These properties are shown in columns - the mapping between column and property is done using the `dataField` attribute of the corresponding DataGridColumn. So, if you know, the name of the particular property of the data that is displayed in column-6, you can update that property to update the column.
Amarghosh
Craig Mc
So what would be the syntax to edit the value of a specific cell at Row 4 Column 3 in the provider?
Craig Mc
@Craig Updated the answer
Amarghosh
@Amarghosh - Thank you soo much I think I can make that work to walk the array lists, and do the updates, the company I work at is excel obsessed i can see by the end of this I would have practically built excel in flex lol. thank you so much.
Craig Mc
I presume getItemAt(requiredRow) = getItemAt(6) where by 6 is the ordinal reference to the row number.
Craig Mc
There should be a button where I can give you a medal or something, that code works perfectly :)
Craig Mc
@Craig You can upvote my answer by clicking the up-arrow `^` button near top-left corner of the answer ;)
Amarghosh
Clicks buttons and stuff :)
Craig Mc