I appreciate the response.

However, what happens when grid1 is sorted differently than grid2?

For example, an item (let's call it "A") might exist at the top of
grid1, but in grid2, "A" exists at the bottom (because the user has
sorted the columns differently.

In this case, setting the verticalScrollPositions the same won't help,
because that'll put it at the top of grid2, which is wrong.  It should
be at the bottom.

I basically want to do this: "Set the scroll position in a grid so
that the currently selected item is visible."

Thoughts?

-Jacob




--- In [email protected], "Tim Hoff" <[EMAIL PROTECTED]> wrote:
>
> 
> 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 [email protected], "j_sevlie" <jsevlie@> 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
> >
>







--
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/
 


Reply via email to