tags:

views:

611

answers:

2

Hey guys

In my application, I have a datagrid that is bound to RemoteObject. The datagrid has a corresponding form that contains the details. When the user clicks on a row in the datagrid the form populates with the values from the DataGrid's selectedItem.

I want to programatically select some row in my DataGrid when the application loads.

In order to do this, I have to call validateNow() and scrollToIndex()

eg.

dg.selectedIndex = i; dg.validateNow();
dg.scrollToIndex(i);

I put this code in the Applications creationComplete handler.

This all works great - the desired row is highlighted and selected and the selectedIndex is i. The problem is that I can't access the data to populate the details form. When I try to retrieve the dg.SelectedItem property - it is null.

How does one programatically select some row in the grid on load AND access the row data?

thanks

A: 

the selected item of the datagrid is just pointing to the item in the dataProvider. If you know which item you want selected in your datagrid, just use that item in your source data to do the initial population of your form.

invertedSpear
Thanks for the reply buddy.But the dataProvider is also null.I can not do this:datagrid.dataProvider[i] or something
Shuo
A: 

use

dg.invalidateList();
dg.callLater(setRows, [1]);

function selRows(indices:Array):void {
  dg.selectedIndices = indices;
  dg.validateNow();
  dg.scrollToRow(indices[0]);
}

Basically if you are changing DG data and selecting an item in the same flow, your seleciton will be overwritten by ListBase methods, you have to set the selections after current GUI update for which you need to use callLater methoad.

scienty