Hi, your original idea of having a [Event] metatag didnt work because DatagridColumn isn't extending from UIObject (i think).
in the click event of your cellrenderer you can add an event listener and dispatch it to the parentdocument (which is probabaly where you want your click event to be handled eg function click(event) { this.addEventListener("myLocalClickHandler", this.parentDocument); this.dispatchEvent({type:"myLocalClickHandler"}); } or something like this. regards bod --- In flexcoders@yahoogroups.com, "mrmcfeely8" <[EMAIL PROTECTED]> wrote: > Ah! Now we're getting closer! I was hoping my little "challenge" > would evoke a response :) Thanks, Ted! > > I'm actually already using all those members of the CellRenderer API > to relay events out to my custom DataGridColumn, but I hadn't thought > of dispatching the events from the DataGrid itself. I'll give that a > try... it definitely seems like the next best alternative. There are > a couple drawbacks to that approach, though, that I'd like to get > around: > > 1) Assuming I use the same CellRenderer for multiple columns in my > DataGrid, my event handler would have to have a few conditional > statements to detect which column the event applies to. Can't say I'm > a big fan of long if/else or switch statements... or maybe I'm being > too picky. > > 2) I don't think I'd be able to use this kind of syntax: > <mx:DataGrid cellEdit="myEventHandler(event)" ... > > I'd rather not have to write out a bunch of explicit addEventHandler() > statements. I know it's just syntactic sugar, but I do have quite a > sweet tooth. > > I'd also rather not extend DataGrid and define a bunch of events with > [Event()] metadata tags (which would enable the type of syntax > above)... at the DataGrid level, it's hard to tell exactly which > events will be dispatched from its cells, since the number and type of > columns is variable... to me, it makes more sense to declare these > events at the DataGridColumn level, which knows exactly what events it > dispatches (based on its Cell Renderer). > > Am I wrong to think that emitting events from a custom DataGridColumn > object should be possible? > > --- In flexcoders@yahoogroups.com, "Theodore E Patrick" <[EMAIL PROTECTED]> > wrote: > > Use a cellrenderer, the cellRenderer API was designed to extends and > provide > > custom inner layout of datagrid cells. > > > > There are some default objects that decorate each CellRenederer > instance: > > > > var listOwner:MovieClip //the datagrid > > var getCellIndex:Function > > var getDataLabel:Function > > var owner:MovieClip //the dataGridColumn instance > > > > These are actually present whether you use a customCellRenderer or > not. So > > in your case simply use these to listen/dispatch the events you > need. Your > > Cellrenderer can add events onto these objects or broadcast events > out to > > the DataGrid as things happen within the CellRenderer. > > > > For example say I have an inner checkbox within my CellRenderer. I > would add > > a click event onto that control where it would do something like > so. > > > > Note: 'com' is my cellRenderers inner component instance: > > > > function click(){ > > > > //obtain the index > > > > var index = getCellIndex() > > > > //obtain the columnName from the Datagrid > > > > var colName = listOwner.getColumnAt( index.columnIndex ).columnName > > > > //edit the data because the component data had changed > > > > listOwner.dataProvider.editField( index.itemIndex , colName , > com.selected ) > > > > //set the dataproviders seletedIndex > > > > listOwner.selectedIndex = index.itemIndex > > > > //trigger a 'celledit' event in the datagrid > > > > listOwner.dispatchEvent( { type:"cellEdit" , cell:this , > column:colName, > > value:com.selected } ) > > > > } > > > > Stump Flexcoders? Think again! :) > > > > Cheers, > > > > Ted ;) > > > > > > > Well, I found you can simply pass a Function object to the custom > > > DataGridCell and have the custom cell handle its own click method > with > > > that Function. The drawback is that the function must live in the > > > same MXML file that the DataGridCell is declared in. I'd still > much > > > rather use Flex's own event handling mechanisms. Any other ideas? > > > Have I stumped the flexcoders?! -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/