Hi Jacob, This should do the trick; without using a loop:
public function keepSelected(event:ListEvent):void { if (grid1.selectedIndex >= 0) { grid2.selectedItem = grid1.selectedItem; grid2.verticalScrollPosition = grid1.verticalScrollPosition; } } -TH --- In flexcoders@yahoogroups.com, "j_sevlie" <[EMAIL PROTECTED]> wrote: > > Hello all, I have a question about our favorite topic -- datagrids! > > This is with Flex 2. > > Let's say that I have 2 identical datagrids, both with the same > dataprovider. What I want to accomplish is when a user selects > something in datagrid1, I want that same item to be selected in > datagrid2, INCLUDING scrolling down to where that item exists. > > Here's the code: > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > layout="absolute"> > > <mx:Script> > <![CDATA[ > import mx.events.ListEvent; > > public function keepSelected(event:ListEvent):void { > > if (grid1.selectedIndex >= 0) { > var i:int, len:int; > len = grid2.dataProvider.length; > > for (i=0; i<len; i++) { > if (grid2.dataProvider[i].oid == > grid1.selectedItem.oid) { > grid2.selectedIndex = i; > // -- [TODO -- > // Figure out how to get the > verticalScrollPosition set correctly. > break; > } > } > } > } > ]]> > </mx:Script> > > <mx:Array id="myData"> > <mx:Object oid="1" region="North" newsales="50" usedsales="25" > parts="15" accessories="10" /> > <mx:Object oid="2" region="South" newsales="40" usedsales="35" > parts="10" accessories="15" /> > <mx:Object oid="3" region="East" newsales="65" usedsales="15" > parts="10" accessories="10" /> > <mx:Object oid="4" region="West" newsales="60" usedsales="20" > parts="15" accessories="5" /> > <mx:Object oid="5" region="North_NEW" newsales="50" > usedsales="25" parts="15" accessories="10" /> > <mx:Object oid="6" region="South_NEW" newsales="40" > usedsales="35" parts="10" accessories="15" /> > <mx:Object oid="7" region="East_NEW" newsales="65" > usedsales="15" parts="10" accessories="10" /> > <mx:Object oid="8" region="West_NEW" newsales="60" > usedsales="20" parts="15" accessories="5" /> > <mx:Object oid="9" region="North_OLD" newsales="50" > usedsales="25" parts="15" accessories="10" /> > <mx:Object oid="10" region="South_OLD" newsales="40" > usedsales="35" parts="10" accessories="15" /> > <mx:Object oid="11" region="East_OLD" newsales="65" > usedsales="15" parts="10" accessories="10" /> > <mx:Object oid="12" region="West_OLD" newsales="60" > usedsales="20" parts="15" accessories="5" /> > </mx:Array> > > > <mx:DataGrid x="10" y="10" id="grid1" > itemClick="keepSelected(event)" height="199" dataProvider="{myData}"> > <mx:columns> > <mx:DataGridColumn headerText="Region" > dataField="region"/> > <mx:DataGridColumn headerText="New Sales" > dataField="newsales"/> > <mx:DataGridColumn headerText="Used Sales" > dataField="usedsales"/> > </mx:columns> > </mx:DataGrid> > > <mx:DataGrid x="320" y="10" id="grid2" height="199" > dataProvider="{myData}"> > <mx:columns> > <mx:DataGridColumn headerText="Region" > dataField="region"/> > <mx:DataGridColumn headerText="New Sales" > dataField="newsales"/> > <mx:DataGridColumn headerText="Used Sales" > dataField="usedsales"/> > </mx:columns> > </mx:DataGrid> > > </mx:Application> > > --- > > Any ideas? I just want to scroll the user down to the place where the > selectedItem is displayed. Is this even possible? > > Thanks, > Jacob > ------------------------ Yahoo! Groups Sponsor --------------------~--> Yahoo! Groups gets a make over. See the new email design. http://us.click.yahoo.com/WktRrD/lOaOAA/yQLSAA/nhFolB/TM --------------------------------------------------------------------~-> -- 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/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) <*> To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] <*> 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/