Flex DataGrid - 我们如何从单元格获取自定义控件的对象

时间:2010-02-02 06:22:31

标签: flex datagrid

我有一个关于从我在数据网格中添加的控件值获取的快速问题 项目渲染以及如何在单击该列的单元格时获取该控制对象。

1 个答案:

答案 0 :(得分:0)

您可以通过此

访问
<mx:DataGrid id="fileGrid" click="onClick(event)" dataProvider="{grpCollection}" width="100%" height="100%">
            <mx:columns>
                <mx:DataGridColumn dataField="labelText" headerText="" visible="{!readOnly}" width="100">
                    <mx:itemRenderer>
                        <mx:Component>
                            <renderers:LinkRendererWithEvent/>
                        </mx:Component>
                    </mx:itemRenderer>
                </mx:DataGridColumn>                    
            </mx:columns>
        </mx:DataGrid>

private function onClick(event:MouseEvent):void
            {
                if (event.target is LinkRendererWithEvent)
                {
                    var linkRenderer:LinkRendererWithEvent = event.target as LinkRendererWithEvent;
                    if (linkRenderer.linkBut.label == "Add")
                    {

                    }
                }
            }

LinkRendererWithEvent.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" doubleClickEnabled="true" doubleClick="doubleClickHandler()" 
    implements="mx.controls.listClasses.IDropInListItemRenderer">
    <mx:Script>
        <![CDATA[
            import mx.controls.Button;
            import mx.controls.DataGrid;
            import mx.events.FlexEvent;
            import com.barcap.customui.constant.NotificationNames;
            import com.barcap.customui.ApplicationFacade;
            import mx.controls.dataGridClasses.DataGridListData;
            import flash.events.Event;
            import mx.controls.listClasses.BaseListData;
            import mx.controls.dataGridClasses.DataGridListData;
            protected var _listData:DataGridListData;

            [Bindable]
            public var labelField:String;
            public var notificationName:String;


            override public function setFocus():void
            {
                trace("called ");
            }

            private function clickHandler(event:MouseEvent):void
            {
                dispatchEvent(event);
            }

            private function doubleClickHandler():void
            {
                owner.dispatchEvent(new MouseEvent(MouseEvent.DOUBLE_CLICK, false, false));
            }

            override public function set data(value:Object):void
            {
                super.data = value;
                setIt(value);
            }

            public function get listData():BaseListData
            {
                return _listData;
            }

            public function set listData(value:BaseListData):void
            {
                _listData = DataGridListData(value);
                invalidateProperties();
            }

            private function setIt(value:Object):void
            {
                if (value && _listData)
                {
                    linkBut.label = value[_listData.dataField];
                }
                else
                {
                    linkBut.label = "";
                }
            }

            override public function drawFocus(isFocused:Boolean):void
            {
                trace("Enter drawFocus");
            }
        ]]>
    </mx:Script>
    <mx:LinkButton id="linkBut" textDecoration="underline" click="clickHandler(event)"/>
</mx:VBox>