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

ArgumentOutOfRangeException on Remove All

3 Answers 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 2
George asked on 20 Mar 2016, 04:47 AM

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 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 . The remove all looks like this.

protected void RemoveAll_Click(object sender, EventArgs e)
{
    HomeGrid.DataSource = null;
    DataService.Factory().RemoveAllMessages(user.orgId);   
    HomeGrid.Rebind();
}

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  RadGrid definition

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

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 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.

George

 

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 24 Mar 2016, 10:05 AM
Hi,

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?

Regards,
Maria Ilieva
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
George
Top achievements
Rank 2
answered on 24 Mar 2016, 02:21 PM

It is a simple delete using an SQL statement.

public void RemoveAllMessages(Guid orgId)
{
    if (orgId.Equals(Guid.Empty)) {
        return;
    }
    using (SqlConnection theConnection = GetConnection()) {
        SqlCommand command = null;
        SqlTransaction deleteTransaction = null;
        try {
            theConnection.Open();
            deleteTransaction = theConnection.BeginTransaction();
            command = new SqlCommand("DELETE FROM OrgMessages WHERE Orgaz = @orgId", theConnection, deleteTransaction);
            command.Parameters.Add(new SqlParameter("@orgId", SqlDbType.UniqueIdentifier)).Value = orgId;
            command.ExecuteNonQuery();
            deleteTransaction.Commit();
        }
        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.

 

0
Maria Ilieva
Telerik team
answered on 29 Mar 2016, 10:42 AM
Hi,

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?

Regards,
Maria Ilieva
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
George
Top achievements
Rank 2
Answers by
Maria Ilieva
Telerik team
George
Top achievements
Rank 2
Share this question
or