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

RadListView Throws ArgumentOutOfRange Exception When Setting Item In ObservableCollection

2 Answers 69 Views
ListView
This is a migrated thread and some comments may be shown as answers.
intellitechcorporation
Top achievements
Rank 1
intellitechcorporation asked on 22 Mar 2017, 04:24 PM

Telerik Support,

It seems when you have an ObservableCollection set as the ItemsSource of a RadListView, the RadListView does not like when you set an item in the ObservableCollection using the index of the item.

 

ex. 

ObCollection[i] = newObject;

I get the following exception:

at Android.Runtime.JavaList.get_Item (System.Int32 index) [0x00013] in /Users/builder/data/lanes/4009/3a62f1ea/source/xamarin-android/src/Mono.Android/Android.Runtime/JavaList.cs:115
at Telerik.XamarinForms.DataControlsRenderer.Android.ListViewAdapter.UpdateCollectionCore (Telerik.XamarinForms.DataControls.RadListView sourceOwner, Com.Telerik.Widget.List.RadListView targetOwner, System.String propertyName, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x001bd] in <65c6ed5e8fb14b688091ad2fdaa0480e>:0
at Telerik.XamarinForms.Common.FacadeAdapterBase`2[S,T].UpdateCollection (System.Object sourceOwner, System.Object targetOwner, System.String propertyName, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00000] in <b09df7d4d5e74454b9482f9e64875b96>:0
at Telerik.XamarinForms.Common.XamarinToNativeControlExtensions.UpdateCollection[T,K] (T nativeElement, K xfЕlement, System.String propertyName, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00028] in <b09df7d4d5e74454b9482f9e64875b96>:0
at Telerik.XamarinForms.DataControlsRenderer.Android.ListViewRenderer.ItemsSource_CollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00011] in <65c6ed5e8fb14b688091ad2fdaa0480e>:0
at Telerik.XamarinForms.DataControls.RadListView.OnItemsSourceCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000a] in <f0d98fc8921f4f449b0a58a0baeb50d3>:0
at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00012] in /Users/builder/data/lanes/4009/3a62f1ea/source/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:288
at AlertPSS.Data.APSSObservableItemCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in <433f2a6adeaf4b85b51b3da650694a41>:0
at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object oldItem, System.Object newItem, System.Int32 index) [0x00000] in /Users/builder/data/lanes/4009/3a62f1ea/source/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:367
at System.Collections.ObjectModel.ObservableCollection`1[T].SetItem (System.Int32 index, T item) [0x00021] in /Users/builder/data/lanes/4009/3a62f1ea/source/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:233
at System.Collections.ObjectModel.Collection`1[T].set_Item (System.Int32 index, T value) [0x00034] in /Users/builder/data/lanes/4009/3a62f1ea/source/mono/mcs/class/referencesource/mscorlib/system/collections/objectmodel/collection.cs:57
at AlertPSS.Transcend.AsyncReturns.AddFilteredIncident (AlertPSS.Client.Client.ClientInc inc, System.Boolean isUpdate, System.Boolean isInitial, System.Boolean isPulldown) [0x0060c] in C:\Users\kgrub\Documents\Visual Studio 2015\Projects\AlertPSS.Transcend\AlertPSS.Transcend\AsyncReturns.cs:1693
at AlertPSS.Transcend.AsyncReturns+<>c__DisplayClass30_0.<ProcessIncidentUpdate>b__0 () [0x0075a] in C:\Users\kgrub\Documents\Visual Studio 2015\Projects\AlertPSS.Transcend\AlertPSS.Transcend\AsyncReturns.cs:1269

 

This convention is used in WPF/Silverlight to keep a bound collection control ordered correctly instead of removing the item and re-adding it.  Should I not be doing it this way in Xamarin?

 

Please let me know if you need any further information, I am using Telerik For Xamarin 2017 R1 (2017.1.10120.233).

 

Thanks!

2 Answers, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 23 Mar 2017, 08:22 PM
Hi Kyle,

I am not able to reproduce this on my end, take a look at my attached demo.

Click the button and the 2nd item in the RadListView is updated using the same approach you use; the item at the 2nd index in the ObservableCollection is updated with a new object at that index (see the button click handler).

At this time it doesn't appear to be related to the RadListView. In your app, if you swap the RadListView with a plain Xamarin Forms ListView, does it still occur?

If you find that it only occurs with the RadList view, can you update the attached demo so that it replicates the problem and send it back to us? That allow us to investigate further.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
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 Feedback Portal and vote to affect the priority of the items
0
intellitechcorporation
Top achievements
Rank 1
answered on 31 Mar 2017, 08:18 PM
Thank you for the quick reply, and sorry it took me so long to get back to you.  I commented this out for now, but I will do some testing and see if I can reproduce it in an isolated environment and whether or not it's strictly related to the RadListView or also affects Xamarin.Forms ListView.
Tags
ListView
Asked by
intellitechcorporation
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
intellitechcorporation
Top achievements
Rank 1
Share this question
or