I'm also not sure why this happens, but if you change the code in
function cc of dg.selectedItem = array[3] to dg.selectedIndex = 3 it
works.

--- In [email protected], "jmfillman" <[EMAIL PROTECTED]> wrote:
>
> Not sure if this is a bug, kind of looks like it, but you can prevent 
> this by doing this:
> 
> <mx:DataGrid id="dg" dataProvider="{array}" 
> itemClick="dg.selectedItem = array[dg.selectedIndex]; ck(event)">
> 
> 
> --- In [email protected], "shafram" <shafram@> wrote:
> >
> > Hello I am encountering a strange problem when I try to select an 
> item
> > after an initial sort order has been provided.
> > 
> > In this example, I have 5 items with all the same count. My initial
> > sorting is on the count field.
> > Once the initial sort has been set, I programmatically select the 
> 4th
> > item in my array which is Letter "D".  If I then try to click on 
> Letter
> > "A" which is right above "D", The alert box will display "D" 
> not "A" in
> > Flex 3.
> > 
> > In flex 2 the event.target.selectedItem is null and an exception is
> > thrown.
> > 
> > Here is the source code. Am I doing something wrong or is this a 
> bug in
> > flex?
> > 
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> > layout="absolute"  creationComplete="cc()">
> > 
> > 
> >      <mx:Script>
> >          <![CDATA[
> >              import mx.controls.Alert;
> >              import mx.events.ListEvent;
> >              import mx.collections.SortField;
> >              import mx.collections.Sort;
> >              import mx.collections.ArrayCollection;
> > 
> >              [Bindable]
> >              private var array : ArrayCollection ;
> > 
> > 
> >              private function cc() : void{
> > 
> >                  array =  new ArrayCollection([
> >                  {"count" : 1207662300, "wp" : "A"},
> >                  {"count" : 1207662300, "wp" : "B"},
> >                  {"count" : 1207662300, "wp" : "C"},
> >                  {"count" : 1207662300, "wp" : "D"},
> >                  {"count" : 1207662300, "wp" : "E"}
> > 
> >              ]);
> > 
> >                  var sorting : Sort = new Sort();
> >                  var sortByCount : SortField = new
> > SortField("count",false,true,true);
> >                  sorting.fields = [sortByCount];
> >                  this.array.sort = sorting;
> >                  this.array.refresh();
> > 
> >                  dg.selectedItem = array[3];
> > 
> > 
> >              }
> > 
> >              private function ck(event : ListEvent) : void {
> > 
> >                     Alert.show(event.target.selectedItem.wp);
> > 
> >              }
> > 
> >          ]]>
> >      </mx:Script>
> > 
> > 
> >      <mx:DataGrid id="dg" dataProvider="{array}" itemClick="ck
> (event)">
> >          <mx:columns>
> >              <mx:DataGridColumn headerText="Count" 
> dataField="count"/>
> >              <mx:DataGridColumn headerText="Letter" dataField="wp"/>
> >          </mx:columns>
> >      </mx:DataGrid>
> > 
> > 
> > </mx:Application>
> >
>


Reply via email to