0

有没有办法确保所选项目在 Spark DataGrid 中可见?

.

上下文
我有一个绑定到数组集合的数据网格。我远程接收到一项服务,该服务为我提供了集合中对象的 ID(字符串)。仅使用我循环遍历集合的字符串来查找与字符串匹配的项目。我通过它的 ID 找到对象。现在我有了要在数据网格中选择的对象。我可以设置

dataGrid.selectedItem = object; 

现在我需要确保它是可见的。我没有行或列索引。

.

更新
使用下面的答案,我用这个功能称赞了它:

    /**
     * Ensures the item is visible (for spark data grid)
     **/
    public function ensureItemIsVisibleInSparkDataGrid(datagrid:spark.components.DataGrid, item:Object):void {
        var list:IList = datagrid.dataProvider;
        var length:int = list.length;
        var itemFound:Boolean;
        var object:Object;
        var index:int;

        for (var i:int;i<length;i++) {
            object = list.getItemAt(i);

            if (object==item) {
                itemFound = true;
                index = i;
                break;
            }
        }

        if (itemFound) {
            datagrid.ensureCellIsVisible(index);
        }
    }
4

1 回答 1

1

Yes, it's called ensureCellIsVisible(). You need to know that row and column of the item in question. To get this to work you'd need to listen for the selectionChange event then calculate the row and column of the currently selected item.

于 2012-08-14T21:57:30.503 回答