This question is locked. New answers and comments are not allowed.
Hi
I have a problem with the databound listbox, when I have one element in the list and I remove it, and I want to add a new element instead I get the following exception:
at Telerik.Windows.Controls.RadDataBoundListBox.GetLastItemCacheIndex()
at Telerik.Windows.Controls.VirtualizationStrategy.RefreshViewportOnItemAdded(IDataSourceItem addedItem)
at Telerik.Windows.Controls.RadVirtualizingDataControl.UpdateViewportOnItemsChange(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Controls.RadVirtualizingDataControl.OnItemsChanged(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Controls.RadDataBoundListBox.OnItemsChanged(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Controls.RadVirtualizingDataControl.OnListSource_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
I have also created a sample application showing what I am doing:
Xaml:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Telerik:RadDataBoundListBox Grid.Row="1" Name="TestListbox" DataVirtualizationMode="OnDemandAutomatic" CacheMode="BitmapCache" ItemsSource="{Binding TestStringCollection}">
<Telerik:RadDataBoundListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</Telerik:RadDataBoundListBox.ItemTemplate>
</Telerik:RadDataBoundListBox>
</Grid>
C#:
namespace RadControlsWindowsPhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
public ObservableCollection<string> TestStringCollection { get; private set; }
// Constructor
public MainPage()
{
InitializeComponent();
TestStringCollection = new ObservableCollection<string>();
TestStringCollection.Add("a");
DataContext = this;
}
private void TestButtonClick(object sender, EventArgs e)
{
TestStringCollection.Remove("a");
TestStringCollection.Add("b"); //Exception here
}
}
}
If I have 2 items in the listbox this doesn't happen.
I would like you to offer a work around this and to fix it as soon as possible. Thanks in advance.
Best Regards Doug
I have a problem with the databound listbox, when I have one element in the list and I remove it, and I want to add a new element instead I get the following exception:
at Telerik.Windows.Controls.RadDataBoundListBox.GetLastItemCacheIndex()
at Telerik.Windows.Controls.VirtualizationStrategy.RefreshViewportOnItemAdded(IDataSourceItem addedItem)
at Telerik.Windows.Controls.RadVirtualizingDataControl.UpdateViewportOnItemsChange(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Controls.RadVirtualizingDataControl.OnItemsChanged(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Controls.RadDataBoundListBox.OnItemsChanged(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Controls.RadVirtualizingDataControl.OnListSource_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
I have also created a sample application showing what I am doing:
Xaml:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Telerik:RadDataBoundListBox Grid.Row="1" Name="TestListbox" DataVirtualizationMode="OnDemandAutomatic" CacheMode="BitmapCache" ItemsSource="{Binding TestStringCollection}">
<Telerik:RadDataBoundListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</Telerik:RadDataBoundListBox.ItemTemplate>
</Telerik:RadDataBoundListBox>
</Grid>
C#:
namespace RadControlsWindowsPhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
public ObservableCollection<string> TestStringCollection { get; private set; }
// Constructor
public MainPage()
{
InitializeComponent();
TestStringCollection = new ObservableCollection<string>();
TestStringCollection.Add("a");
DataContext = this;
}
private void TestButtonClick(object sender, EventArgs e)
{
TestStringCollection.Remove("a");
TestStringCollection.Add("b"); //Exception here
}
}
}
If I have 2 items in the listbox this doesn't happen.
I would like you to offer a work around this and to fix it as soon as possible. Thanks in advance.
Best Regards Doug