LongListSelector throws ArgumentOutofRangeException when I add items to a new group. Please see the code below:
public class ConnectEventByCategory : ObservableCollection<ConnectEventInCategory>
{
public void Add(IConnectEvent connectEvent)
{
var query = (from category in this where (category != null && category.Key == connectEvent.DateTime.Date.ToString()) select category);
if (query.Count() != 0)
{
(query.First() as ConnectEventInCategory).Add(connectEvent);
}
else
{
ConnectEventInCategory newCategory = new ConnectEventInCategory(connectEvent.DateTime.Date.ToString());
this.Add(newCategory);
newCategory.Add(connectEvent);
}
}
}
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at Microsoft.Phone.Controls.LongListSelector.OnAdd(Int32 startingIndex, ItemType itemType, Object group, IList newItems)
at Microsoft.Phone.Controls.LongListSelector.OnGroupCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, IConnectEvent item)
at System.Collections.ObjectModel.Collection`1.Add(IConnectEvent item)
at PeopleConnector.ConnectEventByCategory.Add(IConnectEvent connectEvent)
at PeopleConnector.MainViewModel.LoadData(ConnectEvent oldIEventItem, ConnectEvent newIConnectItem, Action _action)
at PeopleConnector.Connector.AddConnectEvent(ConnectEvent iEventItem)
at PeopleConnector.ConnectEventDetailsViewModel.AddEditConnectEvent()
at PeopleConnector.ConnectEventDetailsViewModel.doneButton_Click(Object sender, EventArgs e)
at PeopleConnector.ConnectEventDetailsPage.doneButton_Click(Object sender, EventArgs e)
at Microsoft.Phone.Shell.ApplicationBarItemContainer.FireEventHandler(EventHandler handler, Object sender, EventArgs args)
at Microsoft.Phone.Shell.ApplicationBarIconButton.ClickEvent()
at Microsoft.Phone.Shell.ApplicationBarIconButtonContainer.ClickEvent()
at Microsoft.Phone.Shell.ApplicationBar.OnCommand(UInt32 idCommand)
at Microsoft.Phone.Shell.Interop.NativeCallbackInteropWrapper.OnCommand(UInt32 idCommand)
Comments: Closing fixed issues.
public class ConnectEventByCategory : ObservableCollection<ConnectEventInCategory>
{
public void Add(IConnectEvent connectEvent)
{
var query = (from category in this where (category != null && category.Key == connectEvent.DateTime.Date.ToString()) select category);
if (query.Count() != 0)
{
(query.First() as ConnectEventInCategory).Add(connectEvent);
}
else
{
ConnectEventInCategory newCategory = new ConnectEventInCategory(connectEvent.DateTime.Date.ToString());
this.Add(newCategory);
newCategory.Add(connectEvent);
}
}
}
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at Microsoft.Phone.Controls.LongListSelector.OnAdd(Int32 startingIndex, ItemType itemType, Object group, IList newItems)
at Microsoft.Phone.Controls.LongListSelector.OnGroupCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, IConnectEvent item)
at System.Collections.ObjectModel.Collection`1.Add(IConnectEvent item)
at PeopleConnector.ConnectEventByCategory.Add(IConnectEvent connectEvent)
at PeopleConnector.MainViewModel.LoadData(ConnectEvent oldIEventItem, ConnectEvent newIConnectItem, Action _action)
at PeopleConnector.Connector.AddConnectEvent(ConnectEvent iEventItem)
at PeopleConnector.ConnectEventDetailsViewModel.AddEditConnectEvent()
at PeopleConnector.ConnectEventDetailsViewModel.doneButton_Click(Object sender, EventArgs e)
at PeopleConnector.ConnectEventDetailsPage.doneButton_Click(Object sender, EventArgs e)
at Microsoft.Phone.Shell.ApplicationBarItemContainer.FireEventHandler(EventHandler handler, Object sender, EventArgs args)
at Microsoft.Phone.Shell.ApplicationBarIconButton.ClickEvent()
at Microsoft.Phone.Shell.ApplicationBarIconButtonContainer.ClickEvent()
at Microsoft.Phone.Shell.ApplicationBar.OnCommand(UInt32 idCommand)
at Microsoft.Phone.Shell.Interop.NativeCallbackInteropWrapper.OnCommand(UInt32 idCommand)
Comments: Closing fixed issues.