This is a migrated thread and some comments may be shown as answers.

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

6 Answers 524 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vincent
Top achievements
Rank 1
Vincent asked on 21 Jun 2012, 08:53 AM
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.





6 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 26 Jun 2012, 06:26 AM
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.
0
Andreas
Top achievements
Rank 1
answered on 18 Jul 2012, 09:13 PM
Hello,

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

thanks,
Thomas

0
Marin
Telerik team
answered on 19 Jul 2012, 07:57 AM
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.
0
Pankaja
Top achievements
Rank 1
answered on 23 Jul 2013, 08:36 PM
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.
0
Marin
Telerik team
answered on 26 Jul 2013, 12:05 PM
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.
0
John
Top achievements
Rank 1
answered on 07 Apr 2015, 09:55 PM
*** Solved ***  I moved the following from the main RadGrid declaration its MasterTableView declaration ...                    AllowAutomaticUpdates="true"
AllowAutomaticInserts="true"
AllowAutomaticDeletes="true"
Tags
Grid
Asked by
Vincent
Top achievements
Rank 1
Answers by
Marin
Telerik team
Andreas
Top achievements
Rank 1
Pankaja
Top achievements
Rank 1
John
Top achievements
Rank 1
Share this question
or