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

Error: Specified argument was out of the range of valid values. Parameter name: ItemHierarchicalIndex trying to recreate a telerik demo solution

1 Answer 269 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kris
Top achievements
Rank 1
Kris asked on 13 Dec 2010, 06:54 PM
I realized I had posted this question in perhaps the wrong forum (here) so I am reposting here in hopes that someone might be able to answer this. Any help would be greatly appreciated!

I am trying to recreate functionality found in this demo from telerik.

When I attempt to drag and drop the available orders to shipped orders I receive an error:
Specified argument was out of the range of valid values. Parameter name: ItemHierarchicalIndex

I have modified very little from the default demo code.  The only change I have made is the GetOrder routine.  Here is my complete code:
<%@ Control Language="C#" ClassName="AddPortalDocs" Inherits="Sage.Platform.WebPortal.SmartParts.EntityBoundSmartPartInfoProvider" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
<telerik:RadAjaxManager runat="server" ID="radAjax" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="grdPendingOrders">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="grdPendingOrders" />
                <telerik:AjaxUpdatedControl ControlID="grdShippedOrders" />
                <telerik:AjaxUpdatedControl ControlID="msg" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="grdShippedOrders">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="grdShippedOrders" />
                <telerik:AjaxUpdatedControl ControlID="msg" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="UseDragColumnCheckBox">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="grdPendingOrders" />
                <telerik:AjaxUpdatedControl ControlID="grdShippedOrders" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
 
<telerik:RadScriptBlock runat="server" ID="scriptBlock">
    <script type="text/javascript">
            <!--
        function onRowDropping(sender, args) {
            if (sender.get_id() == "<%=grdPendingOrders.ClientID %>") {
                var node = args.get_destinationHtmlElement();
                if (!isChildOf('<%=grdShippedOrders.ClientID %>', node) && !isChildOf('<%=grdPendingOrders.ClientID %>', node)) {
                    args.set_cancel(true);
                }
            }
            else {
                var node = args.get_destinationHtmlElement();
                if (!isChildOf('trashCan', node)) {
                    args.set_cancel(true);
                }
                else {
                    if (confirm("Are you sure you want to delete this order?"))
                        args.set_destinationHtmlElement($get('trashCan'));
                    else
                        args.set_cancel(true);
                }
            }
        }
 
        function isChildOf(parentId, element) {
            while (element) {
                if (element.id && element.id.indexOf(parentId) > -1) {
                    return true;
                }
                element = element.parentNode;
            }
            return false;
        }
                -->
    </script>
</telerik:RadScriptBlock>
<div style="float: left; padding: 0 6px 0 10px">
    <h2 style="color: #9c3608">
        Pending Orders</h2>
    <telerik:RadGrid runat="server" ID="grdPendingOrders" OnNeedDataSource="grdPendingOrders_NeedDataSource"
        AllowPaging="True" Width="350px" OnRowDrop="grdPendingOrders_RowDrop" AllowMultiRowSelection="true"
        PageSize="30" EnableHeaderContextMenu="true">
        <MasterTableView DataKeyNames="OrderId" TableLayout="Fixed">
            <Columns>                       
            </Columns>
        </MasterTableView>
        <ClientSettings AllowRowsDragDrop="True" AllowColumnsReorder="true" ReorderColumnsOnClient="true">
            <Resizing AllowColumnResize="true" />
            <Selecting AllowRowSelect="True" EnableDragToSelectRows="false"/>
            <ClientEvents OnRowDropping="onRowDropping" />
            <Scrolling AllowScroll="true" UseStaticHeaders="true"/>
        </ClientSettings>
        <PagerStyle Mode="NumericPages" PageButtonCount="4" />
    </telerik:RadGrid>
</div>
<div style="float: right; padding: 0 10px 0 6px">
    <h2 style="color: #3c8b04">
        Shipped Orders</h2>
    <telerik:RadGrid runat="server" AllowPaging="True" ID="grdShippedOrders" OnNeedDataSource="grdShippedOrders_NeedDataSource"
        Width="350px" OnRowDrop="grdShippedOrders_RowDrop" AllowMultiRowSelection="true">
        <MasterTableView DataKeyNames="OrderId" Width="100%">
            <Columns>                       
            </Columns>
            <NoRecordsTemplate>
                <div style="height: 30px; cursor: pointer;">
                    No items to view</div>
            </NoRecordsTemplate>
            <PagerStyle Mode="NumericPages" PageButtonCount="4" />
        </MasterTableView>
        <ClientSettings AllowRowsDragDrop="True">
            <Selecting AllowRowSelect="True" EnableDragToSelectRows="false" />
            <ClientEvents OnRowDropping="onRowDropping" />
        </ClientSettings>
    </telerik:RadGrid>
</div>
<div style="clear: both;">
    <!-- -->
</div>
<asp:Image runat="server" ID="trashcan" ImageUrl="~/images/icons/recycle-bin-icon-32.gif" ToolTip="Drag selected accounts to here to remove them." />
 
<script runat="server" type="text/C#">
 
     
    public override Sage.Platform.Application.UI.ISmartPartInfo GetSmartPartInfo(Type smartPartInfoType)
    {
        Sage.Platform.WebPortal.SmartParts.ToolsSmartPartInfo ti = new Sage.Platform.WebPortal.SmartParts.ToolsSmartPartInfo();
        ti.Title = "Test";
        return ti;
    }
 
    public Sage.Entity.Interfaces.IAccount CurrentEntity
    {
        get { return this.BindingSource.Current as Sage.Entity.Interfaces.IAccount; }
    }
 
    protected void Page_Load(object sender, EventArgs e)
    { }
 
    protected void Page_Init(object sender, EventArgs e)
    { }
 
    protected void Page_PreRender(object sender, EventArgs e)
    { }
 
    [Sage.Platform.Application.ServiceDependency]
    public new Sage.Platform.Application.IEntityContextService EntityContext { set; get; }
 
    public override Type EntityType
    {
        get { return typeof(Sage.Entity.Interfaces.IAccount); }
    }
 
    protected override void OnAddEntityBindings()
    { }
 
    protected override void OnFormBound()
    {
        base.OnFormBound();
    }
 
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
    protected System.Collections.Generic.IList<Order> PendingOrders
    {
        get
        {
            try
            {
                object obj = Session["PendingOrders"];
                if (obj == null)
                {
                    obj = GetOrders();
                    if (obj != null)
                    {
                        Session["PendingOrders"] = obj;
                    }
                    else
                    {
                        obj = new System.Collections.Generic.List<Order>();
                    }
                }
                return (System.Collections.Generic.IList<Order>)obj;
            }
            catch
            {
                Session["PendingOrders"] = null;
            }
            return new System.Collections.Generic.List<Order>();
        }
        set { Session["PendingOrders"] = value; }
    }
 
    protected System.Collections.Generic.IList<Order> ShippedOrders
    {
        get
        {
            try
            {
                object obj = Session["ShippedOrders"];
                if (obj == null)
                {
                    Session["ShippedOrders"] = obj = new System.Collections.Generic.List<Order>();
                }
                return (System.Collections.Generic.IList<Order>)obj;
            }
            catch
            {
                Session["ShippedOrders"] = null;
            }
            return new System.Collections.Generic.List<Order>();
        }
        set { Session["ShippedOrders"] = value; }
    }
 
    protected void grdPendingOrders_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        grdPendingOrders.DataSource = PendingOrders;
    }
 
    protected System.Collections.Generic.IList<Order> GetOrders()
    {
        System.Collections.Generic.IList<Order> results = new System.Collections.Generic.List<Order>();
        int i = 0;
        Sage.Platform.RepositoryHelper<Sage.Entity.Interfaces.IAccount> repository = Sage.Platform.EntityFactory.GetRepositoryHelper<Sage.Entity.Interfaces.IAccount>();
        Sage.Platform.Repository.ICriteria criteria = repository.CreateCriteria();
        criteria.AddOrder(repository.EF.Asc("AccountName"));
        System.Collections.Generic.IList<Sage.Entity.Interfaces.IAccount> accounts = criteria.List<Sage.Entity.Interfaces.IAccount>();
        foreach (Sage.Entity.Interfaces.IAccount acc in accounts)
        {
            int id = (int)i;
            string customerID = acc.Id.ToString();
            DateTime requiredDate = acc.CreateDate.Value;
            string companyName = acc.AccountName;
            results.Add(new Order(id, customerID, companyName, requiredDate.ToShortDateString()));
            i++;
        }
        return results;
    }
 
    protected void grdShippedOrders_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        grdShippedOrders.DataSource = ShippedOrders;
    }
 
    protected void grdPendingOrders_RowDrop(object sender, GridDragDropEventArgs e)
    {
        if (string.IsNullOrEmpty(e.HtmlElement))
        {
            if (e.DraggedItems[0].OwnerGridID == grdPendingOrders.ClientID)
            {
                // items are drag from pending to shipped grid
                if ((e.DestDataItem == null && ShippedOrders.Count == 0) ||
                    e.DestDataItem != null && e.DestDataItem.OwnerGridID == grdShippedOrders.ClientID)
                {
                    System.Collections.Generic.IList<Order> shippedOrders = ShippedOrders;
                    System.Collections.Generic.IList<Order> pendingOrders = PendingOrders;
                    int destinationIndex = -1;
                    if (e.DestDataItem != null)
                    {
                        Order order = GetOrder(shippedOrders, (int)e.DestDataItem.GetDataKeyValue("OrderId"));
                        destinationIndex = (order != null) ? shippedOrders.IndexOf(order) : -1;
                    }
 
 
                    foreach (GridDataItem draggedItem in e.DraggedItems)
                    {
                        Order tmpOrder = GetOrder(pendingOrders, (int)draggedItem.GetDataKeyValue("OrderId"));
 
                        if (tmpOrder != null)
                        {
                            if (destinationIndex > -1)
                            {
                                if (e.DropPosition == GridItemDropPosition.Below)
                                {
                                    destinationIndex += 1;
                                }
                                shippedOrders.Insert(destinationIndex, tmpOrder);
                            }
                            else
                            {
                                shippedOrders.Add(tmpOrder);
                            }
 
                            pendingOrders.Remove(tmpOrder);
                        }
                    }
 
                    ShippedOrders = shippedOrders;
                    PendingOrders = pendingOrders;
                    grdPendingOrders.Rebind();
                    grdShippedOrders.Rebind();
                }
                else if (e.DestDataItem != null && e.DestDataItem.OwnerGridID == grdPendingOrders.ClientID)
                {
                    //reorder items in pending grid
                    System.Collections.Generic.IList<Order> pendingOrders = PendingOrders;
                    Order order = GetOrder(pendingOrders, (int)e.DestDataItem.GetDataKeyValue("OrderId"));
                    int destinationIndex = pendingOrders.IndexOf(order);
 
                    if (e.DropPosition == GridItemDropPosition.Above && e.DestDataItem.ItemIndex > e.DraggedItems[0].ItemIndex)
                    {
                        destinationIndex -= 1;
                    }
                    if (e.DropPosition == GridItemDropPosition.Below && e.DestDataItem.ItemIndex < e.DraggedItems[0].ItemIndex)
                    {
                        destinationIndex += 1;
                    }
 
                    System.Collections.Generic.List<Order> ordersToMove = new System.Collections.Generic.List<Order>();
                    foreach (GridDataItem draggedItem in e.DraggedItems)
                    {
                        Order tmpOrder = GetOrder(pendingOrders, (int)draggedItem.GetDataKeyValue("OrderId"));
                        if (tmpOrder != null)
                            ordersToMove.Add(tmpOrder);
                    }
 
                    foreach (Order orderToMove in ordersToMove)
                    {
                        pendingOrders.Remove(orderToMove);
                        pendingOrders.Insert(destinationIndex, orderToMove);
                    }
                    PendingOrders = pendingOrders;
                    grdPendingOrders.Rebind();
 
                    int destinationItemIndex = destinationIndex - (grdPendingOrders.PageSize * grdPendingOrders.CurrentPageIndex);
                    e.DestinationTableView.Items[destinationItemIndex].Selected = true;
                }
            }
        }
    }
 
    private static Order GetOrder(System.Collections.Generic.IEnumerable<Order> ordersToSearchIn, int orderId)
    {
        foreach (Order order in ordersToSearchIn)
        {
            if (order.OrderID == orderId)
            {
                return order;
            }
        }
        return null;
    }
 
    protected void grdShippedOrders_RowDrop(object sender, GridDragDropEventArgs e)
    {
        if (!string.IsNullOrEmpty(e.HtmlElement) && e.HtmlElement == "trashCan")
        {
            System.Collections.Generic.IList<Order> shippedOrders = ShippedOrders;
            bool deleted = false;
            foreach (GridDataItem draggedItem in e.DraggedItems)
            {
                Order tmpOrder = GetOrder(shippedOrders, (int)draggedItem.GetDataKeyValue("OrderId"));
 
                if (tmpOrder != null)
                {
                    shippedOrders.Remove(tmpOrder);
                    deleted = true;
                }
            }
            if (deleted)
            {
                DialogService.ShowMessage("Deleted");
            }
            ShippedOrders = shippedOrders;
            grdShippedOrders.Rebind();
        }
    }
 
    #region Nested type: Order
 
    protected class Order
    {
        private string _companyName;
        private string _customerId;
        private int _orderId;
        private string _date;
 
        public Order(int orderId, string customerId, string companyName, string requiredDate)
        {
            _orderId = orderId;
            _customerId = customerId;
            _companyName = companyName;
            _date = requiredDate;
        }
 
        public int OrderID
        {
            get { return _orderId; }
        }
 
        public string CustomerID
        {
            get { return _customerId; }
        }
 
        public string Company
        {
            get { return _companyName; }
        }
 
        public string Date
        {
            get { return _date; }
        }
    }
 
    #endregion
  
</script>
 
              
   

The complete server error is:

2010-12-13 11:50:10,491 ERROR Global - Unhandled exception.
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: ItemHierarchicalIndex
   at Telerik.Web.UI.GridItemCollection.get_Item(String hierarchicalIndex)
   at Telerik.Web.UI.GridDataItemCollection.get_Item(String hierarchicalIndex)
   at Telerik.Web.UI.RadGrid.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 16 Dec 2010, 02:41 PM
Hi Kris ,

Please refer to the following forum thread which elaborates on this matter and see if it helps to avoid this error:
http://www.telerik.com/community/forums/aspnet/grid/38401-specified-argument-was-out-of-the-range-of-valid-values-parameter-name-itemhierarchicalindex.aspx


Regards,
Maria Ilieva
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Kris
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or