R – flex: editing datagrid information

apache-flexdatagrid

I have a simple datagrid that is importing an xml file. I have an edit button at the end of each row, when clicked it brings up an editable form with that rows information in it. I am using event listeners to pass the information back to the main datagrid. The only think i don't understand is, how do you update the datafield values in the datagrid.

I've tried a lot of different things, variations on

myDatagrid.nameField.text = "Person's Name"
nameField[1].text = "Person's name"

Anybody know how I can target the specific rows of the datagrid to edit the values in them?

I have looked a little into data binding, but I can't figure out how to bind the form (in a seperate class) to the datagrid in the main mxml file. So, not sure if this is the way to go.

Best Answer

You would be better off binding on a dataProvider for your dataGrid. Assuming your data is coming from an ArrayCollection:

[Bindable] private var myData:ArrayCollection = new ArrayCollection();

then in your MXML:

<mx:DataGrid dataPrivider="{myData}" ...>

with the curly brace it's now bound so any changes to your myData var automatically update in your grid. Then your edit form can update your myData var directly. I'm not sure what your problem is with binding to something in another class, you may have to bind your form to something like

Application.application.myData

If you really want to avoid the data binding and needed to target a specific row you can probably just grab the selectedItem of your dataGrid. So it would be more like

myDatagrid.selectedItem.nameField.text = "Person's name"
Related Topic