David Wolever
David Wolever

Reputation: 154664

Flex: Get an item from a AdvancedDataGrid given an index

I've got a subclass of AdvancedDataGrid showing a tree-like data structure. How can I, given the index returned by calculateDropIndex, get the item at that index?

After reading through reams of code, it seems like the least terrible way is:

var oldSelectedIndex:int = this.selectedIndex;
var mouseOverIndex:int = this.calculateDropIndex(event);
this.selectedItem = mouseOverIndex;
var item:* = this.selectedItem;
this.selectedIndex = oldSelectedIndex;

The other option seems to be tinkering around with the iterator property... But, judging by the way I've seen it used, that will get pretty harry pretty quickly too.

So, how can I get the item at a particular index in an advanced datagrid without going insane?

Upvotes: 1

Views: 5430

Answers (2)

DenisH
DenisH

Reputation: 889

You could try:

// Get the dropIndex from the dragEvent
var index:int = this.calculateDropIndex(event);
// Get the itemRenderer from the index
var renderer:IListItemRenderer = this.indexToItemRenderer(index);
// Get your item from the data property of the itemRenderer
var item:Object = renderer.data;

Upvotes: 4

CookieOfFortune
CookieOfFortune

Reputation: 14004

this.dataProvider.getItemAt(calculateDropIndex(event));

Looking through the docs, it seems you may be able to use openNodes, which returns an Array of all open nodes, which should correspond with your index?

this.dataProvider.openNodes[calculateDropIndex(event)];

Upvotes: 0

Related Questions