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;
}
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;
}
相关文章推荐
- How do I fix "selector not recognized" runtime exceptions when trying to use category methods from a static library?
- How to get DataKey, RowIndex or Row from a GridView row event
- 关于incompatible types when assigning to type "a"from type "b"的bug修复
- [How To] Remove deleted records from Main Index in Sphinx
- 有趣的文章:Will Intel be forced to remove the "cripple AMD" function from their compiler?
- QT21 Display selected row from QTableView to QlineEdit
- How to get the Values of Selected Row from a Gridview using ASP.NET
- How to uninstall IE7 by commands when it failed to uninstall Internet Explorer 7 from Add/Remove pro
- How to get the data from a cell when I click on the GridButtonColumn of the same row
- SharePoint 2007 (MOSS/WSS) - how to remove "Download a Copy" context menu from a Document Library
- SharePoint自动化系列——Add/Remove "Record" from items
- How to fix the issue "A problem has been encountered while loading the setup components. Canceling setup"?
- How to remove the "Active" marked on partitions
- reason: '-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object
- Get Selected Row Values From Kendo Grid On Change Event
- Add/Remove ISAPI Filter to/from IIS Automatically Using Delphi
- ZZ: How to remove 'Open in Windows Explorer' from the 'Actions Menu'
- "Unable to get image data from canvas because the canvas has been tainted by cross-origin data"问题产生原
- 编译器&调试---安装Android SDK遇到"folders failed to rename or remove"
- iOS开发 - "Cast from pointer to smaller type 'int' loses information” 解决办法