Ah, your items are XML, that is fine, I am personally quite fond of XML.
First, what line is throwing that error? Also, make this change: var xmlItem:Object = XML(event.currentTarget.selectedItem); and change oItem to xmlItem everywhere in that function too. This toggles the checkbox, is that what you want? oit...@selected = (oit...@selected == 'true') ? false : true; Tracy Spratt, Lariat Services, development services available _____ From: [email protected] [mailto:[email protected]] On Behalf Of fumeng5 Sent: Tuesday, April 14, 2009 3:48 PM To: [email protected] Subject: [flexcoders] Re: Access DataGridColumn on DataGrid Row Click Thank you, this is working very well now except for one bug: When I click directly on the checkbox I get the following error: Property @selected not found on Boolean and there is no default value. Meaning that 'oItem', instead of coming back as an object (event.currentTarget.selectedItem) is being set to a Boolean value. This also happens, albeit inconsistently, on a row click when the row doesn't appear to have focus. note: I change oItem.selected to oit...@selected because the DP 'selected' is an attribute, not a property. here's the updated code (and thank you again!): private function onItemClick( event:ListEvent ):void { var oItem:Object = event.currentTarget.selectedItem; oit...@selected = (oit...@selected == 'true') ? false : true; var coll:XMLListCollection = myDG.dataProvider as XMLListCollection; coll.itemUpdated(oItem); //this is required when you directly set an item property } --- In flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com, "Tracy Spratt" <tspr...@...> wrote: > > 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: 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 1:32 PM > To: flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.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" <tspratt@> 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. <http://www.cflex.net/> 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> > > >

