Why are you trying to bind a datagrid? That is a display object. A far better way is to pass in the arraycollection the datagrid is based on. Then just create the datagrid in your custom component.
--- In [email protected], "Keith Hughitt" <keith.hugh...@...> wrote: > > Hi all, > > I have been working on my first custom ActionScript component and have > been trouble getting the data-binding setup properly. > > I am trying to making a "FilterManager" component which will enable to > the user to filter based on one or multiple columns in a DataGrid. In > order to do this though I need to be able to bind a DataGrid to the > component. I have not been able to figure out how to do this though, and > was hoping someone might be able to help shed some light. > > Here is the code for the component, and the MXML used to instantiate the > component: > > <custom:FilterManager datagrid="{Application.application.dgResults}" > test="Test String" width="100%" height="100%"/> > > /***********************************************************************\ > ******** > * Filter Manager > > ************************************************************************\ > ******/ > package custom { > > import mx.containers.Form; > import mx.containers.FormItem; > import mx.controls.Alert; > import mx.controls.DataGrid; > import mx.utils.ObjectUtil; > import flash.events.Event; > > > > /***********************************************************************\ > **** > * Class definition for a class to manage the various search filters > > ************************************************************************\ > ***/ > public class FilterManager extends Form { > > [Bindable] > public var datagrid:DataGrid; > > private var _test:String; > > private var filterSettings:Array; > > > /*********************************************************************** > * FilterManager (Constructor) > * > * Creates an instance of the filter manager class > > ***********************************************************************/ > public function FilterManager():void { > super(); > this.initFilters(); > } > > [Bindable] > public function set test(value:String):void > { > _test = value; > } > > public function get test():String > { > return _test; > } > > > /*********************************************************************** > * initFilters > * > * Builds an array to manage the different filters that may be > set > > ***********************************************************************/ > private function initFilters():void { > this.filterSettings = new Array(); > > for each (var col:* in this.datagrid.columns) { > var d:Object = new Object(); > > if (col['dataField'] != null) { > d.field = col['dataField']; > d.enabled = false; > d.filter = null; > this.filterSettings.push(d); > } > } > } > > > /*********************************************************************** > * component overrides > > ***********************************************************************/ > override protected function createChildren():void { > super.createChildren(); > for each (var item:Object in this.filterSettings) { > var f:FormItem = new FormItem(); > f.label = item.field; > addChild(f); > } > Alert.show("createChilden()"); > } > > override protected function commitProperties():void { > super.commitProperties(); > } > > override protected function measure():void { > super.measure(); > } > > override protected function > updateDisplayList(unscaledWidth:Number, > > unscaledHeight:Number):void { > super.updateDisplayList(unscaledWidth,unscaledHeight); > } > > } > } > I've tried passing in data both via public variables (the "datagrid" > field), and using the preferred accessor & mutator route ("test"), but > have not had any luck with either. > > Can anyone please tell me what the proper way to bind a DataGrid in the > application to the custom component so that I can reference it in the > initFilters function? > > Any help would be greatly appreciated. > > Thanks! > Keith >

