You are very close. But setItemAt requires an entire item, not just the changed property. While setItemAt might be better practice, I would just set the property directly, and then call itemUpdated:
private function onItemClick( event:ListEvent ):void { var oItem:Object = event.currentTarget.selectedItem; oItem.selected = true; var coll:XMLListCollection = myDG.dataProvider as XMLListCollection; coll.itemUpdated(oItem); //this is required when you directly set an item property } Tracy Spratt, Lariat Services, development services available _____ From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of fumeng5 Sent: Tuesday, April 14, 2009 1:32 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Access DataGridColumn on DataGrid Row Click Tracy, Thank you for your response. I've got the checkbox renderer from cflex and it's working just fine. i've updated my XMLListCollection with the 'selected' property and it renders fine as well. The problem is updating the collection on click of a datagrid row. Here is what I have: private function onItemClick( event:ListEvent ):void { // update the dataprovider using the collection API var e:ListEvent = event; var rowIndex:Number = e.rowIndex; var coll:XMLListCollection = myDG.dataProvider as XMLListCollection; coll.setItemAt({selected:true},rowIndex); } I don't appear to be setting the correct object. Do I wanted to be setting the datagrid's selectedItem instead? and here is my XMLListCollection. <mx:dataProvider> <mx:XMLListCollection> <mx:source> <mx:XMLList xmlns=""> <data col1="haha" selected="false"/> <data col1="hahaha" selected="true"/> <data col1="hahahaha" selected="true"/> </mx:XMLList> </mx:source> </mx:XMLListCollection> </mx:dataProvider> Thank you very much for your help. --- In flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com, "Tracy Spratt" <tspr...@...> wrote: > > You need to study up on item renderers a bit. What you are trying to do > will not work. The check box state must be driven by a value in the > dataProvider item. You should not attempt to access the check box directly > via code. > > > > Find an example of a checkbox renderer, there are many, I have one on > www.cflex.net <http://www.cflex. <http://www.cflex.net/> net/> . Do not attempt to create an > interactive itemRenderer from scratch > > > > When you have a working renderer, you can simply set the property on the > dataProvider item (using the collection API, or itemUpdated()) > > > > Tracy Spratt, > > Lariat Services, development services available > > _____ > > From: flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com [mailto:flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com] On > Behalf Of fumeng5 > Sent: Tuesday, April 14, 2009 9:56 AM > To: flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com > Subject: [flexcoders] Access DataGridColumn on DataGrid Row Click > > > > > > > > > Hi, > > I'm trying to access a DataGridColumn when a user clicks on a DataGrid row. > The problem is that I'm not trying to access the column that was clicked > on.... > > I want to select a checkbox that is always in the 2nd column whether a user > clicks on the 2nd column or not. I'm having trouble figuring out how to do > that......Can anyone point me in the right direction? > > Thanks! > > <mx:DataGrid id="myDG" width="100%" height="100%" > itemClick="onItemClick(event)"> > > <mx:dataProvider> > <mx:XMLListCollection> > <mx:source> > <mx:XMLList xmlns=""> > <data col1="haha" col2=""/> > <data col1="hahaha" col2=""/> > <data col1="hahahaha" col2=""/> > </mx:XMLList> > </mx:source> > </mx:XMLListCollection> > </mx:dataProvider> > > <mx:columns> > > <mx:DataGridColumn headerText="col1" dataField="@col1"/> > > <mx:DataGridColumn headerText="col2" dataField="@col2"> > <mx:itemRenderer> > <mx:Component> > <mx:CheckBox label="Check this Box!" /> > </mx:Component> > </mx:itemRenderer> > </mx:DataGridColumn> > > </mx:columns> > > </mx:DataGrid> >