This content has been marked as final. Show 6 replies
Looks like there is a bug in the Datagrid - you can have selectedItem != null and no selected rows on the screen in the datagrid.
Only in rare situations can you set selectedItem.
It will only work when you set it to a *reference* to an actual item in the dataProvider. You cannot set it to an object that simply has the same properties.
To select an item using a property value of the dataProvider, yo must loop over the dataProvider and compare the value to the appropriate property, then use that indes to set selectedIndex.
The Value I am setting is an actual data from dataProvider - my example shows that comparison in the second case returns true.
The bottom line is selectedItem = x does not work, and using selectedIndex = getSomehowIndex(x) works. In both cases x is the same object.
Bug in the DataGrid?
How are you setting m_Value?
It does not matter if it is "actual data from dataProvider ", it must be a *reference* to a dataProvider item.
The loop in the second case is the way you must do this.
Now, this would work:
dg_List.selectedItem = dg_List.dataProvider.getItemAt(2); //because it is settin it to a reference
If you look closely at the second option you can see that there is a comparison between getItemAt() and m_Value and it passes successfully. In the same time selectedItem = m_Value fails. All values here are refs to the same object.
OK, the task is - add new value to the dataprovider and make it selected in the grid. Easy.
I don't want to use second method (looping through values) because dataProvider is very large array and Flex perfomance is not the thing you should ignore.
And yes, bugs database contains around 20 bugs in this area, but they all "hidden".