Oh sweet.. you fixed it. I didn't even know there is such thing called ViewCourser. Thanks heaps!! It works perfectly fine on my system too.
About being to complicated.. that's exactly what I reckon. Even though the Flex components are really powerful, it's sometimes a pain in the ass to achieve some simple goals. I think you have to know the component's structure very well to get all the good things out of it, otherwise it takes ages. Cheers, Max ----- Original Message ---- From: Muzak <[EMAIL PROTECTED]> To: flexcoders@yahoogroups.com Sent: Monday, December 24, 2007 4:28:19 AM Subject: Re: [flexcoders] Re: Select next DataGrid item after one removed > If you sort by a column in your example it doesn't work > anymore either. Yeah I noticed that too :( You'll have to use a Sort and ViewCorsor to make this work. You'll also have to uase callLater in order to set the new selected index after removing the selected item. Tried a few things with the earlier mentioned disableAutoUpdate/enableAutoUpdate, but can't seem to get it right with a Sort and ViewCursor. Either the selectedIndex gets set properly, but the view (datagrid) isn't update properly (the item is visually not selected, but tracing dg.selectedIndex returns the correct value), or the datagrid does show a selectedItem (visually), but not the correct one. Using a delay (callLater) fixes that, but then you may run into problems when hitting the delete button continously (allthough it works fine here). All in all, I think this is much more complicated than it should be. The following seems to work: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="appInit();" > <mx:Script> <![CDATA[ import mx.utils.ObjectUtil; import mx.collections.SortField; import mx.collections.IViewCursor; import mx.collections.Sort; private var fnSort:Sort; private function appInit():void { trace("Application ::: appInit"); // create sort on lastname var fnSort:Sort = new Sort(); fnSort.fields=[new SortField("lastname")]; // apply sort to collection ac.sort = fnSort; ac.refresh(); } private function deleteClickHandler(evt:Event):void { trace("Application ::: deleteClickHandler"); var index:int = dg.selectedIndex; trace(" - index: "+index); var item:Object = dg.selectedItem; var vc:IViewCursor = ac.createCursor(); trace(" - cursor: "+vc); // move viewcursor to selected dg item vc.findFirst(item); trace(" - current: "+ObjectUtil.toString(vc.current)); // remove current item in ViewCursor // you'll need to check if item is valid before removing it vc.remove(); ac.refresh(); callLater(refreshIndex, [index]); } private function refreshIndex(value:int):void { trace("Application ::: refreshIndex"); // make sure to check if value is valid (not out of bounds) trace(" - value: "+value); dg.selectedIndex = value; trace(" - selectedIndex: "+dg.selectedIndex); } ]]> </mx:Script> <mx:ArrayCollection id="ac"> <mx:Object firstname="Jimi" lastname="Hendrix" dataID="0" /> <mx:Object firstname="Frank" lastname="Zappa" dataID="1" /> <mx:Object firstname="Miles" lastname="Davis" dataID="2" /> <mx:Object firstname="Harry" lastname="Connick Jr." dataID="3" /> <mx:Object firstname="John" lastname="Coltrane" dataID="4" /> <mx:Object firstname="Dizzy" lastname="Gillespie" dataID="5" /> <mx:Object firstname="Charlie" lastname="Parker" dataID="6" /> <mx:Object firstname="Jimi" lastname="Hendrix" dataID="7" /> <mx:Object firstname="Frank" lastname="Zappa" dataID="8" /> <mx:Object firstname="Miles" lastname="Davis" dataID="9" /> <mx:Object firstname="Harry" lastname="Connick Jr." dataID="10" /> <mx:Object firstname="John" lastname="Coltrane" dataID="11" /> <mx:Object firstname="Dizzy" lastname="Gillespie" dataID="12" /> <mx:Object firstname="Charlie" lastname="Parker" dataID="13" /> </mx:ArrayCollection> <mx:VBox> <mx:DataGrid id="dg" dataProvider="{ac}" /> <mx:Button id="delete_btn" label="delete" click="deleteClickHandler(event)" /> </mx:VBox> </mx:Application> ----- Original Message ----- From: "m.frigge" <[EMAIL PROTECTED]> To: <flexcoders@yahoogroups.com> Sent: Sunday, December 23, 2007 11:27 AM Subject: [flexcoders] Re: Select next DataGrid item after one removed Hrr, this thing is driving me nuts. I found out why it is not working in my Application. It is because I sort by column as soon as the Data is loaded. If you sort by a column in your example it doesn't work anymore either. How can I fix this? Greets, Max -- 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 ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping