4 Replies Latest reply on Feb 14, 2008 6:48 AM by tata6688

    hierarchical  AdvancedDataGrid : selecting a specific index

    tata6688
      I'm trying to select some items displayed in a hierarchical AdvancedDataGrid. The underlying items in the dataProvider have been replaced but using their id I want to select them back in the AdvancedDataGrid.

      1) The dataGrid is displayed and item id #123 is selected
      2) The datatGrid's dataprovider is replaced
      3) I want to select item #123 back in the dataGrid

      To do this, I loop over the new dataProvider and I compare the ID (#123) to find the new instance of the item that should be selected. Then I do:

      ------
      myDataGrid.selectedItem = newItem;
      ------

      But it doesn't seem to work for a reason I don't understand. I did a lot of tests using all the 'validate()', 'invalidate()' and 'refresh()' methods I could find but nothing worked.

      But, if I use the index instead :

      -----
      var newIndexToSelect:int = newDataProvider.getItemIndex(newItem);
      myDataGrid.selectedIndex = newIndexToSelect;
      ------

      It does work! But only if the dataProvider is an ArrayCollection! It doesn't work if it's a HierarchicalCollectionView. And I need to use GroupingCollection to create my dataProvider because I use the tree feature of the AdvancedDataGrid.

      When the dataProvider is a HierarchicalCollectionView, I have no idea how to select the correct index in the Grid! Some of the row in my tree-grid are not actual items but 'groups' so I can't map the indices of my actual items in the Collection's source to the indices in the datagrid!

      Any help or tips on how to select a particular index in a hierarchical AdvancedDataGrid ?

      Thanks a lot!

      JL