tags:

views:

256

answers:

1

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.

A: 

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"
invertedSpear
Thanks,Yeah I feel like data binding is the way to go, but I guess I'd like to know how to do both. I'll try the data binding, but for the myDataGrid.selectedItem... does that only work for the clicked item? Like If i am returning the data from an event listener in the form, then will it still know what the selected item is?
Brent
@Brent - couldn't be sure without testing, but Unless you de-select it, it should remain selected. If it doesn't you could also pass the selectedIndex to the form, then when you're data is returning it, set the selectedIndex, Unless your DP changed you should end up with the same item selected.
invertedSpear
Well, just as a follow-up, I got the data binding working between the form and the datagrid, that is a beautiful thing in flex.
Brent
Binding is one of the strongest features. So much automation in one little word. By the Way if my answer has helped you, it is customary on SO to accept it by clicking the check mark and possibly an up-vote.
invertedSpear