A click event is a bubbling event. Therefore, anyone listening to click on the DG will see it. However, they'll also see clicks on scrollbars and other parts of the DG. But if the click handler does a test
if (event.target is DPFileRenderer) Then it will know that the button got clicked. An alternative is to make a custom event and dispatch it. -Alex ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Joseph Abenhaim Sent: Thursday, March 01, 2007 11:33 AM To: [email protected] Subject: [flexcomponents] Button renderer in datagrid cell Hi guys, I have a datagrid with a custom button renderer built in Actionscript. I'm trying to figure out how to capture the click event of the component when the button is clicked. I'm generating the component from the cell depending on the type of field: column.itemRenderer = new ClassFactory(DpFileRenderer); The actual component: package joe.ui { import mx.controls.Button; import flash.events.MouseEvent; import flash.events.Event; public class DpFileRenderer extends Button { [Embed("/assets/icons/drive_disk.png")] private var diskIcon:Class; [Embed("/assets/icons/drive_disk_grey.png")] private var diskIconDisabled:Class; override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth, unscaledHeight); this.label = this.listData.label; if(this.listData.label != '0') { this.setStyle("icon", diskIcon); } else { this.setStyle("icon", diskIconDisabled); this.enabled = false; } this.labelPlacement = "left"; this.setStyle("color", 0x000000); } } } I'm not exactly sure on where to put an event broadcast in there that fires when the user clicks on the button. Could anybody help? Thanks. From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Steve Gustafson Sent: Thursday, March 01, 2007 2:16 PM To: [email protected] Subject: Re: [flexcomponents] Struggling with itemRenderer in DataGrid OK, now I've gotten rid of the VBox, but still do not see how I can set a different dataProvider to the comboBox, or dynamically set the selectedIndex. Again any help is greatly appreciated. Steve On 3/1/07, Alex Harui <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote: Your itemRenderer is not a ComboBox, it is a VBox containing a ComboBox. The DataGrid sets the .data property on the VBox and you haven't written the code to pass it on down to the ComboBox. You can either write that code, or use ComboBox as the top-level tag so you are really using a subclass of ComboBox as the renderer, which is the recommended practice. -Alex ________________________________ From: [EMAIL PROTECTED] <mailto:[email protected]> [mailto:flexcompone [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> ] On Behalf Of Steve Gustafson Sent: Thursday, March 01, 2007 3:45 AM To: [EMAIL PROTECTED] <mailto:[email protected]> Subject: [flexcomponents] Struggling with itemRenderer in DataGrid Help. I posted this on FlexCoders with no response, so I thought I would try here too. I'm trying to use an itemRenderer to create a comboBox in a DataGrid that is being created with AS. I can create the comboBox, but I am struggling with being able to change the dataProvider for the rendered comboBox, and setting the selected index on the comboBox. The relevant code I am using is below. Any help is GREATLY APPRECIATED as I am rapidly approaching a deadline. Steve public function createPositionTable():void { _datagrid = positionsGrid; // positionsGrid is an already created DataGrid object _col1 = new DataGridColumn; _col2 = new DataGridColumn; _col3 = new DataGridColumn; _col4 = new DataGridColumn; _col5 = new DataGridColumn; _col1.headerText= "Position"; _col1.dataField = "Description"; _col1.editable = true; _col1.width = 100; _col2.dataField = "Type"; _col2.headerText= "Type"; _col2.editable = true; _col2.width = 50; _col3.dataField = "levelCode"; _col3.headerText = "Level Code"; _col3.width = 150; _col3.editable = false; _col3.itemRenderer = new ClassFactory(cbRender); // HERE IS WHERE I AM CREATING THE COMBO BOX _col3.editorDataField = "levelCode"; _columns = new Array(_col1,_col2,_col3); _datagrid.columns = _columns _datagrid.sortableColumns = false; _datagrid.dataProvider = objAdminTableGridDP; _datagrid.dragEnabled = false; _datagrid.dragMoveEnabled = false; _datagrid.dropEnabled = false; _datagrid.editable = true; _datagrid.rowHeight = 30; updateTablesButton.label = 'Update Positions Table'; } ------------------------------------ cbRender.mxml <?xml version="1.0" encoding="utf-8"?> <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " width="50" height="25"> <mx:Script> <![CDATA[ import mx.utils.ObjectUtil; [Bindable] public var myLevels:Array = [{label:"Accounting", data:"accounting"}, {label:" Administator", data:"1"}, {label:"Programmer", data:"2"}, {label:"Vice President", data:"3"}, {label:"President", data:"4"},]; public var cboLevelID:String = ''; public function get setLevel():String { return cboLevels.selectedItem.data; } ]]> </mx:Script> <mx:ComboBox id="cboLevels" dataProvider="{myFolders}"/> </mx:VBox> ________________________________ size=1 width="100%" align=center> Under Florida law, e-mail addresses are public records. If you do not want your e-mail address released in response to a public records request, do not send electronic mail to this entity. Instead, contact this office by phone or in writing.
