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

Problem after removing item from itemssource

10 Answers 518 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Henk
Top achievements
Rank 1
Henk asked on 25 Sep 2009, 01:04 PM
Hi,

I have a problem when I remove an item from the ItemsSource of the RadGridView.
In the RadGridView there is a column with deletebuttons to delete a specific row. 
Steps to reproduce the problem:

The ItemsSource (populated with 5 items) is bound to the RadGridView.
Click on the last item in the RadGridView.
Click on the deletebutton of one of the first 4 items.
Then an exception is thrown (index out of range) on Rebind

This is the code for the delete button click event:       
        private void btnDeleteRow_Click(object sender, RoutedEventArgs e)  
        {  
            ((Button)sender).IsEnabled = false;  
            var gridViewRow = ((Button)sender).ParentOfType<GridViewRow>();  
             
            if (gridViewRow != null)
            {  
                if (gridViewRow.IsInEditMode) gridViewRow.CancelEdit();  
                dataList.Remove(gridViewRow.DataContext);  
                radGridView.Rebind();  
            }  
            
        } 

 

 

 
if the item to delete is the current item there is no problem.

 

10 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 30 Sep 2009, 09:08 PM
Hi Henk Boen,

We are currently investigating the issue and we will update you on our progress. Could you just share with us what kind of data you are using as ItemsSource? It is a simple List, an ObservableCollection, or something else?

Kind regards,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Milan
Telerik team
answered on 02 Oct 2009, 06:34 AM
Hello Henk Boen,

Could you send us the exact error message and stack trace that you are getting? That will help us to resolve the problem.

In the meantime you could try the following workaround which will even make the code more concise. If possible, you can bind the grid to an ObservableColletion which will eliminate the need to rebind the grid when some element is removed because RadGridView will automatically detect this and  update its UI. If the grid is bound to an ObservableCollection the code will look like that:

private void btnDeleteRow_Click(object sender, RoutedEventArgs e)     
        {     
            ((Button)sender).IsEnabled = false;     
            var gridViewRow = ((Button)sender).ParentOfType<GridViewRow>();     
                
            if (gridViewRow != null)   
            {     
                if (gridViewRow.IsInEditMode) gridViewRow.CancelEdit();     
                dataList.Remove(gridViewRow.DataContext);     
            }     
               
        }   

Hope this helps.

Greetings,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Henk
Top achievements
Rank 1
answered on 02 Oct 2009, 10:28 AM
Hi,

The problem exists when using a List as Itemssource.
This is the Stack Trace:
System.ArgumentOutOfRangeException was unhandled by user code  
  Message="Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index" 
  StackTrace:  
       at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)  
       at System.ThrowHelper.ThrowArgumentOutOfRangeException()  
       at System.Collections.Generic.List`1.get_Item(Int32 index)  
       at System.Collections.Generic.List`1.System.Collections.IList.get_Item(Int32 index)  
       at Telerik.Windows.Data.EnumerableExtensions.ElementAt(IEnumerable source, Int32 index)  
       at Telerik.Windows.Data.QueryableCollectionView.InternalGetItemAt(Int32 index)  
       at Telerik.Windows.Data.QueryableCollectionView.GetItemAt(Int32 index)  
       at Telerik.Windows.Data.QueryableCollectionView.get_CurrentItem()  
       at Telerik.Windows.Data.Selection.SelectionHandler.InitializeCurrentItem()  
       at Telerik.Windows.Controls.DataControl.InitializeSelection()  
       at Telerik.Windows.Controls.GridView.GridViewDataControl.InitializeSelection()  
       at Telerik.Windows.Controls.GridView.GridViewDataControl.LoadData()  
       at Telerik.Windows.Controls.GridView.GridViewDataControl.OnCollectionViewCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)  
       at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)  
       at Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)  
       at Telerik.Windows.Data.QueryableCollectionView.RefreshAndRaiseCollectionChanged(NotifyCollectionChangedEventArgs args)  
       at Telerik.Windows.Data.QueryableCollectionView.Refresh()  
       at Telerik.Windows.Controls.DataControl.Rebind()  
       at Formulier.FormVraagGridControl.btnDeleteRow_Click(Object sender, RoutedEventArgs e)  
       at System.Windows.Controls.Primitives.ButtonBase.OnClick()  
       at System.Windows.Controls.Button.OnClick()  
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)  
       at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)  
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName) 

If I use an ObservableCollection as a workaround there is no problem.

If I use a List as Itemssource and make the Item to remove the CurrentItem before removing there is also no problem:
        private void btnDeleteRow_Click(object sender, RoutedEventArgs e)  
        {  
            var gridViewRow = ((Button)sender).ParentOfType<GridViewRow>();  
            if (gridViewRow != null)  
            {  
                radGridView.CurrentItem = gridViewRow;  
                if (gridViewRow.IsInEditMode) gridViewRow.CancelEdit();  
                dataList.Remove(gridViewRow.DataContext);  
                radGridView.Rebind();  
            }  
        }  
 
0
Milan
Telerik team
answered on 06 Oct 2009, 06:41 AM
Hello Henk Boen,

Thank you very much for the valuable information. We have logged the issue and we will try to fix it as soon as possible.
I hope that you will be able to use the workaround for the time being.

Once again thank you for the feedback. I have updated your Telerik points.

Best wishes,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Steve Y
Top achievements
Rank 2
answered on 19 Nov 2009, 10:56 PM
Hi,

I'm hitting a similar issue. I'm getting an index out of range if I try to add a new item to a QueryableCollectionView once it's been bound to a grid. If I use a PagedCollectionView then it works.

Sequence of events are:

  1. Extract a table from the domaincontext and make it into a QueryableCollectionView. At this point I can add or remove rows from the underlying view without it failing.
  2. Bind the collection to a gridview. Paging, filtering etc works fine.
  3. I then trying to do an insert on AddingNewDataItem. In code behind I add a new row to the underlying view and it fails.

If I repeat the same thing but with a PagedCollectionView it all works perfectly but I don't get 'proper' filtering on the whole data source -  just filtering on the current page.

The line it fails on is member.rtp_Properties.Add(p); I've changed this to be a simple context.rtp_Properties.Add(p) but it still fails.

Are you close to understanding the issue or even fixing it?

Thanks, Steve

var view = new QueryableCollectionView(context.rtp_Properties); 
rgvProperties.ItemsSource = view
... 
 
 
private void rgvProperties_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e) 
        {             
            if (e.Row is GridViewNewRow) 
            {                 
                var p = newProperty
 
                rtp_Members member = context.rtp_Members.First(m => m.UserId == WebContext.Current.User.UserId); 
 
                pp.CreatedBy = p.ModifiedBy = WebContext.Current.User.UserId; 
                pp.CreatedOn = p.ModifiedOn = DateTime.Today; 
                //p.OwnerId = WebContext.Current.User.UserId; 
                p.TeamId = WebContext.Current.User.TeamId; 
 
                member.rtp_Properties.Add(p); 
                context.SubmitChanges(); 
            } 
        } 
 
 
0
Milan
Telerik team
answered on 25 Nov 2009, 12:42 PM
Hello Steve Y,

It seems that my colleague has already responded to your inquiry. You can find the answer here.


Best wishes,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Steve Y
Top achievements
Rank 2
answered on 25 Nov 2009, 02:14 PM
Milan,

This is very frustrating. I posted this on the 19th and I just got a response today, the 25th - which is 6 days. The question that was answered in the post you link sent me to is not related to this question at all.

My frustration is that I will have to wait even longer to get a reply to my question - which is a very serious issue with the control.

Regards, Steve :-(

0
Milan
Telerik team
answered on 26 Nov 2009, 12:55 PM
Hello Steve Y,

Please accept my apologies - somehow I got confused that the problems are related and I am deeply sorry for that. 

We have simulated your scenario in a sample project and we have found one problematic issue  - the RowEditEnded event was called multiple times. We have fixed the faulty code and the fix will be available this Friday with our latest internal build. 

In regard to the index out of range exception, we have recently fixed a similar issue and we were unable to reproduce the exception in our sample application. The chances are that this is issue is resolved and you shouldn't not get such errors once you upgrade to our latest assemblies.

Thank you reporting the issues and once again sorry for the misunderstanding. I have updated your Telerik points.


Best wishes,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Josep Bonet
Top achievements
Rank 1
answered on 12 Feb 2010, 09:11 AM
I am getting this error when trying to commit the edited cell with Tab key insted of Enter. I am using ObservableCollection and Telerik 2009.3.1314.1030 version controls. The following error is thrown after rowEditEnded is handled. Any ideas or workaround for this?
I tried to use later internal built but that have more problems in Grid Scrolling and did not resolve this so I needed to backout to this above release. 
 
private void ParametersListGrid_RowEditEnded(object sender, RowEditEndedEventArgs e)  
{  
        switch (e.EditAction)   
        {  
            case GridViewEditAction.Commit :   
            {  
                var operType = e.EditOperationType;   
                var newValue = e.NewData as UIBatchParameter;   
                (this.DataContext as BatchWizardParametersViewModel).ChangeParameterValue(newValue.BatchParameter);   
                 break;   
                 // the exception is thrown after this in Telerik DLL, see the exception below.  
            }  
            case GridViewEditAction.Cancel:   
            {  
                this.ValidationSummary.Errors.Clear();   
                break;   
            }  
            default :   
            {  
                break;   
            }  
       }  

 


throw

 

new Error("Unhandled Error in Silverlight 2 Application Index was out of range. Must be non-negative and less than the size of the collection.\nParameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)\n at System.ThrowHelper.ThrowArgumentOutOfRangeException()\n at System.Collections.Generic.List`1.get_Item(Int32 index)\n at System.Collections.Generic.List`1.System.Collections.IList.get_Item(Int32 index)\n at Telerik.Windows.Data.EnumerableExtensions.ElementAt(IEnumerable source, Int32 index)\n at Telerik.Windows.Data.QueryableCollectionView.InternalGetItemAt(Int32 index)\n at Telerik.Windows.Data.QueryableCollectionView.GetItemAt(Int32 index)\n at Telerik.Windows.Data.QueryableCollectionView.get_CurrentItem()\n at Telerik.Windows.Data.Selection.SelectionHandler.SynchronizeCurrentItem()\n at Telerik.Windows.Data.Selection.SelectionHandler.SetCurrentItem(Object item)\n at Telerik.Windows.Controls.DataControl.NotifyIsCurrentChanged(DataControl dataControl, RadRowItem container, RadRoutedEventArgs e)\n at Telerik.Windows.Controls.DataControl.ProcessCurrentChangedEvent(RadRowItem rowItem, RadRoutedEventArgs e)\n at Telerik.Windows.Controls.DataControl.OnIsCurrentChanged(Object sender, RadRoutedEventArgs e)\n at Telerik.Windows.RadRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)\n at Telerik.Windows.RadRoutedEventArgs.InvokeHandler(Delegate handler, Object target)\n at Telerik.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RadRoutedEventArgs routedEventArgs)\n at Telerik.Windows.RouteItem.InvokeHandler(RadRoutedEventArgs routedEventArgs)\n at Telerik.Windows.EventRoute.InvokeHandlersImpl(Object source, RadRoutedEventArgs args, Boolean raisedAgain)\n at Telerik.Windows.EventRoute.InvokeHandlers(Object source, RadRoutedEventArgs args)\n at Telerik.Windows.RadRoutedEventHelper.RaiseEvent(DependencyObject element, RadRoutedEventArgs args)\n at Telerik.Windows.DependencyObjectExtensions.RaiseEvent(DependencyObject element, RadRoutedEventArgs e)\n at Telerik.Windows.Controls.RadRowItem.IsCurrentChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)\n at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)\n at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)\n at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason)\n at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)\n at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)\n at Telerik.Windows.Controls.RadRowItem.set_IsCurrent(Boolean value)\n at Telerik.Windows.Controls.GridView.GridViewRow.IsInEditModeChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)\n at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)\n at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)\n at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason)\n at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)\n at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)\n at Telerik.Windows.Controls.GridView.GridViewRow.set_IsInEditMode(Boolean value)\n at Telerik.Windows.Controls.GridView.EditContext.OnCellEditModeChanged(GridViewCell cell, Boolean newIsInEditMode)\n at Telerik.Windows.Controls.GridView.GridViewCell.IsInEditModeChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)\n at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)\n at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)\n at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason)\n at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)\n at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)\n at Telerik.Windows.Controls.GridView.GridViewCell.set_IsInEditMode(Boolean value)\n at Telerik.Windows.Controls.GridView.EditContext.SwitchCellToEditMode(GridViewCell cell)\n at Telerik.Windows.Controls.GridView.EditContext.BeginEdit(GridViewCell gridViewCell)\n at Telerik.Windows.Controls.GridView.GridViewCell.BeginEdit()\n at Telerik.Windows.Controls.GridView.GridViewDataControl.ProcessTabKeyDirection(FocusNavigationDirection focusNavigationDirection)\n at Telerik.Windows.Controls.GridView.GridViewDataControl.ProcessTabKey()\n at Telerik.Windows.Controls.GridView.GridViewDataControl.OnKeyDown(KeyEventArgs e)\n at System.Windows.Controls.Control.OnKeyDown(Control ctrl, EventArgs e)\n at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)");

 

 

 

 

0
Milan
Telerik team
answered on 18 Feb 2010, 01:06 PM
Hello Josep Bonet,

Is DataLoadMode set to Asynchronous by any chance? Judging by the stack trance this a bug that has already been fixed. The fix will be available this Friday with our Internal Build.

You have mentioned that you are experiencing scrolling issue with our Internal Build. Could you elaborate a bit?

Best wishes,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Henk
Top achievements
Rank 1
Answers by
Milan
Telerik team
Henk
Top achievements
Rank 1
Steve Y
Top achievements
Rank 2
Josep Bonet
Top achievements
Rank 1
Share this question
or