Yes, I want a user to be able to continuously select and unselect the checkbox.
And casting the selectedItem to XML now suppresses that error but I am still unable to select/unselect the checkbox. It seems that when I mouse over a row when i'm in the 2nd column, the row isn't being highlighted. so as a result of the row not getting the event, i am unable to select the checkbox. however, the rollover and selection works if i'm in the 1st column. hmmmm....what am i missing? here's the DP and my DataGrid. <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> <mx:DataGridColumn headerText="col1" dataField="@col1"/> <mx:DataGridColumn headerText="col2" dataField="@selected" itemRenderer="com.test.CheckboxRenderer" /> thank you. --- In flexcoders@yahoogroups.com, "Tracy Spratt" <tspr...@...> wrote: > > 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: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On > Behalf Of fumeng5 > Sent: Tuesday, April 14, 2009 3:48 PM > To: flexcoders@yahoogroups.com > 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" <tspratt@> 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> > > > > > >