Hi,

I didn't post on Royale mailing list for a while.
Very busy.

I use VirtualList and VirtualDataGrid however they are not perfect.

One thing that always bothered me was that if I need for example to remove
an element of the list, then I need to refresh the dataProvider and I have
to notify the List, losing the selectedItem and scroll position. This gives
a very bad experience to the user.

I finally put time on this and did this working for me.
Works on the top item (the easy ones), works on the middle of the list (the
chalange ones because it's a Virtual container) and also works for the last
item.
The code it's not 100% beatutifull for the eye (the reason to not push to
the repository), however the issue is also chalanging.
If someone have the same issue as I did, here my solution (for now).
Next I will do the same for DataGrid and should be similar to this solution.

If someone have a more elegant solution or find out an improvement that I
missed, please reply.

public function refresh():void
{
var index:int = selectedIndex;
var top:int = element.scrollTop;

var oldDataProvider:Object = dataProvider;
dataProvider = null;
dataProvider = oldDataProvider;

if ((dataProvider as IArrayList).length > 0)
{
selectedIndex = index;
element.scrollTop = top;
//during the tests I found some inconsistence, so it's need a delay before
select the item
setTimeout(function():void
{
var itemRenderer:IItemRenderer = (view as
VirtualListView).getItemRendererForIndex(selectedIndex);
if (itemRenderer != null)
itemRenderer.element.click();
}, 500);
setFocus();
}
}

Reply via email to