ArgumentOutOfRangeException on Remove All

4 posts, 0 answers
  1. George
    George avatar
    73 posts
    Member since:
    Oct 2014

    Posted 19 Mar Link to this post

    I am implementing a RadGrid that lists admin information messages.  Each row has a row delete X and I have a Remove All button.  The single row deletes work fine but the Remove All gives a ArgumentOutOfRangeException after the delete.

    [ArgumentOutOfRangeException: capacity was less than the current size.
    Parameter name: value]
       System.Collections.ArrayList.set_Capacity(Int32 value) +11392869
       Telerik.Web.UI.GridTableView.GetEnumerator(Boolean useDataSource, GridEnumerableBase resolvedDataSource, ArrayList dataKeysArray, Boolean shouldClearDataKeys) +450
       Telerik.Web.UI.GridTableView.GetJsonData(Int32 startRowIndex, Int32 maxRowsCount) +1013
       Telerik.Web.UI.RadGrid.InitializeDesktopGridTableViewData(GridTableView tableView, Dictionary`2 data) +2181
       Telerik.Web.UI.RadGrid.InitializeGridTableViewData(GridTableView tableView) +105
       Telerik.Web.UI.RadGrid.InitializeGridTableViewsRecursive(GridTableView tableView) +95
       Telerik.Web.UI.RadGrid.DescribeProperties(IScriptDescriptor descriptor) +4419
       Telerik.Web.UI.RadGrid.DescribeComponent(IScriptDescriptor descriptor) +49
       Telerik.Web.UI.RadCompositeDataBoundControl.Telerik.Web.IControl.DescribeComponent(IScriptDescriptor descriptor) +42
       Telerik.Web.UI.ScriptRegistrar.GetScriptDescriptors(Control control) +210
       Telerik.Web.UI.ScriptRegistrar.GetScriptDescriptors(WebControl control) +36
       Telerik.Web.UI.RadCompositeDataBoundControl.GetScriptDescriptors() +35
       Telerik.Web.UI.RadCompositeDataBoundControl.System.Web.UI.IScriptControl.GetScriptDescriptors() +51
       System.Web.UI.ScriptControlManager.RegisterScriptDescriptors(IScriptControl scriptControl) +490
       System.Web.UI.ScriptManager.RegisterScriptDescriptors(IScriptControl scriptControl) +55
       Telerik.Web.UI.RadCompositeDataBoundControl.RegisterScriptDescriptors() +83
       Telerik.Web.UI.RadCompositeDataBoundControl.RenderContents(HtmlTextWriter writer) +67
       Telerik.Web.UI.RadGrid.RenderContents(HtmlTextWriter writer) +102
       Telerik.Web.UI.GridBaseDataList.Render(HtmlTextWriter writer) +132
       Telerik.Web.UI.RadGrid.Render(HtmlTextWriter writer) +217
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +66  ... lots more ...

    I am creating my grid completely from C# code with a very minimal grid definition in the aspx. The remove all looks like this.

    protected void RemoveAll_Click(object sender, EventArgs e)
        HomeGrid.DataSource = null;

    This is my grid definition without the columns

    RadGrid adminGrid = HomeGrid;
    adminGrid.NeedDataSource += new GridNeedDataSourceEventHandler(AdminGrid_NeedDataSource);
    adminGrid.Skin = "Default";
    adminGrid.AutoGenerateColumns = false;
    adminGrid.EnableViewState = false;
    adminGrid.GroupingEnabled = false;
    adminGrid.AllowPaging = true;
    adminGrid.PageSize = 500;
    adminGrid.Height = Unit.Percentage(100);
    adminGrid.EnableHeaderContextMenu = true;
    adminGrid.AllowSorting = true;
    adminGrid.AllowFilteringByColumn = true;
    adminGrid.AllowMultiRowSelection = false;
    adminGrid.AllowAutomaticDeletes = true;
    adminGrid.ClientSettings.EnableRowHoverStyle = true;
    adminGrid.ClientSettings.Selecting.AllowRowSelect = true;
    adminGrid.ClientSettings.Selecting.EnableDragToSelectRows = true;
    adminGrid.ClientSettings.ReorderColumnsOnClient = true;
    adminGrid.ClientSettings.AllowColumnsReorder = true;
    adminGrid.ClientSettings.ColumnsReorderMethod = GridClientSettings.GridColumnsReorderMethod.Reorder;
    adminGrid.ClientSettings.Virtualization.EnableVirtualization = true;
    adminGrid.ClientSettings.Virtualization.InitiallyCachedItemsCount = 2000;
    adminGrid.ClientSettings.Scrolling.AllowScroll = true;
    adminGrid.ClientSettings.Scrolling.UseStaticHeaders = true;
    adminGrid.ClientSettings.Scrolling.ScrollHeight = Unit.Percentage(100);
    adminGrid.ClientSettings.Resizing.AllowColumnResize = true;
    adminGrid.PagerStyle.Mode = GridPagerMode.NextPrevNumericAndAdvanced;
    adminGrid.GroupingSettings.CaseSensitive = false;

    and this my aspx RadGrid definition

    <asp:panel runat="server" ID="HomeGridPanel"  CssClass="windowPercent" >
                <telerik:RadGrid runat="server" ID="HomeGrid"  OnItemCommand="HomeGrid_ItemCommand"></telerik:RadGrid>

    I looked at other posts and could not figure out anything to do about this.   I added AllowAutomaticDeletes based on searches which did not help.

    How can I get rid of the ArrayList ArgumentOutOfRangeException when the Grid goes from having data to no data on a Rebind()?

    On removing single rows going from 1 to zero works fine but Remove All gives the error on one row.  I think the difference is the single row remove is done from an OnItemCommand RadGrid call while the Remove All is done from a server button click method.



  2. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 24 Mar Link to this post


    Can you please share the"RemoveAllMessages" method declaration and the whole RadGrid  configuration so that we can further research on the problem and advise yo for the possible reason of this error?

    Maria Ilieva
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. George
    George avatar
    73 posts
    Member since:
    Oct 2014

    Posted 24 Mar Link to this post

    It is a simple delete using an SQL statement.

    public void RemoveAllMessages(Guid orgId)
        if (orgId.Equals(Guid.Empty)) {
        using (SqlConnection theConnection = GetConnection()) {
            SqlCommand command = null;
            SqlTransaction deleteTransaction = null;
            try {
                deleteTransaction = theConnection.BeginTransaction();
                command = new SqlCommand("DELETE FROM OrgMessages WHERE Orgaz = @orgId", theConnection, deleteTransaction);
                command.Parameters.Add(new SqlParameter("@orgId", SqlDbType.UniqueIdentifier)).Value = orgId;
            catch (Exception ex) {
                DatabaseThrowError(this.ToString(), command, ex);

    That removes all messages associated with the organisation messages being displayed in the grid. 

    The data source for the grid is done with...

    protected void AdminGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
       HomeGrid.DataSource = DataSource;


    DataSource is an object of type public class AdminHomeData : System.Data.DataTable

    The AdminHomeData DataSource object exists and  is empty on the Rebind()..

    Considering it feels like an internal bug in the Telerik software, I worked around it by refreshing the page and getting rid of the crashing Rebind() when removing all messages. Removing 1 message rebinds fine.


  5. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 29 Mar Link to this post


    Can you pleas elaborate on how exactly the columns are added to the rad grid control, as i suppose that the programmatically added columns might cause the issue on your end?

    Maria Ilieva
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top