您的位置:首页 > 产品设计 > UI/UE

A issue related to "incorect SelectedIndex when remove a row from DataGrid"

2009-03-20 12:06 477 查看
Ref to: http://www.airia.cn/FLEX_Directory/accessing_xml_data/2/

This is a KNOWN issue, when you remove a row from a datagrid and set next row as "selected" with SelectedIndex, sometime a "并非所愿" item is selected, the following is the solution:

1. remove the item from data source

2. define a function to flush the data source to grid, and reset the selectedIndex

2. use callLater to call the function.

the following is a sample:

private function deleteBookHandler():void
{
// Save the currently selected index.
var selectedBookIndex:int = myDataGrid.selectedIndex;

// Delete the currently selected book.

delete (myBooks.book[selectedBookIndex]);

// Reselect the next logical item in the data grid.
newSelectedIndex = (selectedBookIndex==0) ? 0 : selectedBookIndex - 1;

// Change the selected index of the data grid

// at a later frame. See note on changeDataGridIndex()
// method for more details on this workaround.
callLater ( changeDataGridIndex );
}

// This is a workaround for a known issue with
// List-based components where deleting an item
// from the control's dataProvider leaves the

// selectedIndex at an incorrect value. The workaround
// is to reassign the data provider at least a
// frame later and to change the index there.
private function changeDataGridIndex ():void
{

// Reassign the data grid's data provider.
myDataGrid.dataProvider = myBooks.book;

// Set the selected index.
myDataGrid.selectedIndex = newSelectedIndex;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐