8 Replies Latest reply on Nov 19, 2009 10:00 AM by toms@polycom

    DataGrid SelectedItems empty when should have entries

    toms@polycom

      Hi,

       

      I have a DataGrid with allowMultipleSelection="true" but I can recreate a scenario where the user selects multiple items from the grid but the selectedItems.length==0 instead of the number of selected items.

       

      To replicate:

       

      Declare the grid with allowMultipleSelection="true" and change="changeGrid()"

      Start with an empty grid

      Add items to it dynamically

      Add a breakpoint in the changeGrid() function

      Perform a multi-select.

      Check the selectedItems in the changeGrid() function.  The length is 0.

       

      If I leave the screen and come back, the new items are displayed correctly.  When I do a multi-select at this point, selectedItem.length == the number of items selected so its correct at this point although the code didn't change.

       

      Why, when the grid is empty, does the selectedItems appear not to work properly?  Is there something else I should be doing to the grid?

       

      In the code I assign the dataProvider to a list (can be empty) and add items via other actions in the app.  The selectedItems and selectedIndices are initialized as follows:

       

              override public function postLayout():void
              {  
                  dataGrid.selectedIndices = new Array();
                  dataGrid.selectedItems = new Array();
                  dataGrid.selectedItem = null;
                  dataGrid.selectedIndex = -1;

              }

       

      selectedItems only seems to return a length == 0 if the grid was empty prior to adding entries to the dataProvider list.

       

      Has anyone else seen this previously?

       

      Is this a bug in flex or is there something I'm not doing in the code that causes this?

       

      Thanks, in advance, for the help.