I have a dataProvider from a list. The list has the selecteIndex Binded from a var -selectedDamageIdx. I am changing the selectedDamageIdx and more or less and at the same I move items arround in the list. When everything is over the index is not correct but the value on the selectedDamageIdx is correct. Any suggestions? I made sure the selectedDamageIdx is public and bindable. The Binding is done in mxml.
My list is a damage list. It uses a damage itemRenderer and a damage Object. Basically, what I am doing is: I have a thumbail with the same information as the list. When I drag something around in the thumbnail to move items, I want the list to update the item positions. I have a function called onChangePosition as following where I have access to the _from and _to positions. So I do the following:
if(_to > _from)
{
(damages.dataProvider as ArrayCollection).addItemAt(damage,_to);
(damages.dataProvider as ArrayCollection).removeItemAt(_from);
selectedDamageIdx = _to-1;//because of shift all the items between the _from and _to will move back one position. And the moved item will actually get the index to-1
}
else if (_from > _to)
{
(damages.dataProvider as ArrayCollection).removeItemAt(_from);
(damages.dataProvider as ArrayCollection).addItemAt(damage,_to);
selectedDamageIdx = _to;
}
This works fine on the thumbnail and the selectedDamageIdx gets the expected value. But, I think because of my add and remove operation the list selects the wrong item, and the selectedIndex is wrong. On the first case where _to > _from the selectedIndex on the list is one less than it should be. On the second case where _to < _from the selectedIndex is one more than it should be.