Expanded hierarchical grid hit error "Specified argument was out of the range of valid values. Parameter name: ItemHierarchicalIndex"

7 posts, 0 answers
  1. Vincent
    Vincent avatar
    1 posts
    Member since:
    Jun 2012

    Posted 21 Jun 2012 Link to this post

    Hi Telerik team,

    I'm using Radgrid to build a tree structure with source of objects with parent and child relationship, 
    and the configuration of the grid as below:

    MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
    MasterTableView.HierarchyDefaultExpanded = false;
    MasterTableView.SelfHierarchySettings.KeyName = "xxx";
    MasterTableView.SelfHierarchySettings.ParentKeyName = "yyy";
     
    ClientSettings.AllowExpandCollapse = true;
    ClientSettings.AllowColumnsReorder = false;
    ClientSettings.ReorderColumnsOnClient = true;

    Everything works fine until when one of the node is expanded to more that 1 level, and refresh the page (based on some criteria so that the data source now has changed), the following error appears:

    Specified argument was out of the range of valid values. Parameter name: ItemHierarchicalIndex

    Some additional info on the error:

    Source Telerik.Web.UI
    Function Telerik.Web.UI.GridDataItem get_Item(System.String)
    Stack Telerik.Web.UI.GridDataItemCollection.get_Item(String hierarchicalIndex)
    Telerik.Web.UI.RadGrid.LoadClientState(Dictionary`2 clientState) 
    System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad)
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


    myGrid_ClientState {"selectedIndexes":[],"reorderedColumns":[],"expandedItems":["1","1","0","0","1","1","0","0","1","1","0","0","0:0_10","0"],"expandedGroupItems":[],"expandedFilterItems":[],"deletedItems":[],"hidedColumns":[],"showedColumns":[],"popUpLocations":{},"draggedItemsIndexes":[]}


    Apparently the problem is on client state data "expandedItems", i guess it is trying to restore the expanded items on the new data source (which has been changed and the expanded levels in client data may not be valid anymore).

    I'm not quite sure about my observation, but i've tried to override the LoadClientState function in my custom grid:

    protected override bool LoadClientState(Dictionary<string, object> clientState)
            {
                if (clientState.ContainsKey("expandedItems"))
                    clientState["expandedItems"] = new object[] { };
                return base.LoadClientState(clientState);
            }

    It does the trick and the page is successfully refreshed no matter how many level of nodes i expanded before.
    However i would like to know is there any better solution for this, and why does this happen?

    Thanks.





  2. Marin
    Admin
    Marin avatar
    1043 posts

    Posted 26 Jun 2012 Link to this post

    Hello,

     This happens because you change the datasource and the grid persists the indexes of the expanded items - but when the datasoure is changed some of the indexes may not be valid anymore. Your approach is a good workaround in this case because it clears the expanded items indexes related to the previous datasource.

    Kind regards,
    Marin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Thomas Roithmeier
    Thomas Roithmeier avatar
    17 posts
    Member since:
    Jul 2010

    Posted 18 Jul 2012 Link to this post

    Hello,

    I have the exact same problem, but in a wpf radgridview. What is the workaround for the WPF-radgridview?

    thanks,
    Thomas

  5. Marin
    Admin
    Marin avatar
    1043 posts

    Posted 19 Jul 2012 Link to this post

    Hi,

     Please open a formal support ticket for WPF GridView - this way it will be addressed from my colleagues as fast as possible. 

    All the best,
    Marin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Pankaja
    Pankaja avatar
    1 posts
    Member since:
    May 2013

    Posted 23 Jul 2013 Link to this post

    Where do I call the LoadClientState method? I have the same issue as Vincent on expanding the nested view from there on any action I do on the page I get the ItemHierarchicalIndex - out of range error. Do I call the LoadClientState in the pre-render or init and where in my UserControl or the parent page? FYI, I have the RADGrid within a usercontrol and whenever I expand and do any other action on the parent page I get the error.
  7. Marin
    Admin
    Marin avatar
    1043 posts

    Posted 26 Jul 2013 Link to this post

    Hello,

     In the previous case the issue was caused by a  modification of the data source on postback. Note that this is not fully supported scenarios and you should not replace the data source of the control or the structure of the grid on postback because a lot of structure related information for the control is stored in the viewstate and if the structure changes you may get various errors on postback.
    If the reason for the exception is different in your case you can further check the server-side logic to see if there is any code that depends on the ItemHierarchicalIndex of the item and might cause such issues.
    Overriding the default LoadClientState method of the control is only applicable in case you are extending the RadGrid in a custom class, but this may not be suitable in all cases because this way you will clear the expanded state of the items, which may result in unwanted user experience.

    Regards,
    Marin
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  8. John
    John avatar
    43 posts
    Member since:
    Aug 2014

    Posted 07 Apr 2015 Link to this post

    *** Solved ***  I moved the following from the main RadGrid declaration its MasterTableView declaration ...                    AllowAutomaticUpdates="true"
    AllowAutomaticInserts="true"
    AllowAutomaticDeletes="true"
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017