This one has nailed me several times this week, so …
The Flash MX 2004 DataGrid component allows for the browsing and editing of data, including data retrieved from ColdFusion (via Flash Remoting or SOAP). Data grids are typically populated by datasets (which in turn are populated using connectors or ActionScript code). The relationship between datasets and data grids is rather tenuous, to the point that scrolling or changing position in a data grid does not automatically change the position in the dataset. This is rather counter-intuitive, and means is that if you attempt to programmatically obtain information about the currently highlighted record, you may get the wrong row. Similarly, if you “delete the current row in a grid” you may delete the wrong row from the dataset. The solution? You must explicitly instruct the data grid and dataset to stay in synch by binding selectedIndex property of each of them to each other, this way as you move within the grid the internal dataset pointer moves too.

5 thoughts

  1. We need more docs on using the new flash ui components, binding –not to mention a flash remoting connector from MM.

  2. I have noticed the problem too, but cannot get your solution to work. I have implicitly bound the selectedIndex of the dataGrid to the dataSet using all variations (in, out, in/out) on both, but still the selected record always is one iteration behind. If you select the row again it is correct, but if you select the next row, it will display the data from the previous selection first. It seems to be laggin one record behind.
    How do I explicitly bind these to components together?

  3. Got it! I explicitly tell the dataSet to sync with the dataGrid in actionscript:
    myDataSet_ds.selectedIndex = myDataGrid_dg.selectedIndex;
    ie.
    listenerObject = new Object();
    listenerObject.change = function(eventObject) {
    myDataSet_ds.selectedIndex = myDataGrid_dg.selectedIndex;
    trace(myDataSet_ds.currentItem.user_ID);
    };
    myDataGrid_dg.addEventListener("change", listenerObject);

Leave a Reply