在Flex中查找datagrid / adavancedDataGrid行的x,y位置

时间:2010-02-27 00:34:27

标签: flex datagrid flex3 row advanceddatagrid

我有flex advancedDataGrid(如果效果更好,可以使用dataGrid,虽然我喜欢我的元列标题),并且我希望在所选行的顶部有一个组件弹出窗口。

问题是,我可以弄清楚如何引用数据网格的实际渲染行(而不是数据提供者的项目),以便在屏幕上获得它的位置。

有没有人有关于如何访问数据网格“行”的理论,或者至少得到它的位置?

干杯

3 个答案:

答案 0 :(得分:1)

我们最终在引用父文档的itemrender中执行此操作。基本上,单击时,项呈示器将在父项中唤起一个函数,并引用自身。

此时我们的父文档知道选择了哪个单元格,我们做了一些操作来确定它的x,y坐标:

public function showPopup(selectedItemRenderer:UIComponent):void {
        selectedCell = selectedItemRenderer;

        PopUpManager.removePopUp(editPopup);

        editPopup.height = dg.rowHeight;

        BindingUtils.bindProperty(editPopup, "width", dg, "width");

        editPopup.setStyle("backgroundColor", 0xFF0000);
        if(selectedCell != null) {
            editPopup.x = selectedCell.localToGlobal(new Point(0,0)).x - 1;
            editPopup.y = selectedCell.localToGlobal(new Point(0,0)).y - 1;
        }

        PopUpManager.addPopUp(editPopup, DisplayObject(Application.application));

    }

<mx:DataGrid id="dg" width="500" height="100%"
    dataProvider="{dummyData2}">
<mx:columns>        
    <mx:DataGridColumn
        width="60">
        <mx:itemRenderer>
            <mx:Component>
                <mx:HBox>
                    <mx:Button label="edit" click="{parentDocument.showPopup(this)}" />
                </mx:HBox>                          
            </mx:Component>
        </mx:itemRenderer>
    </mx:DataGridColumn>
    <mx:DataGridColumn 
        dataField="Category">
    </mx:DataGridColumn>     
</mx:columns>

答案 1 :(得分:1)

我在dataGridColumn中使用了width属性,只是将宽度加在一起得到x位置,但问题是当你使用lockColumnCount时我的程序没有正确找出x。

答案 2 :(得分:0)

获取datagrid的x,y位置的简单方法是将数据网格包装在画布中并尝试捕获canvasX的mouseX和mouseY。如有必要,您可以使用localToGlobal方法。

相关问题