Unplanned
Last Updated: 04 Oct 2024 12:34 by Martin Ivanov
Martin Ivanov
Created on: 04 Oct 2024 12:34
Category: DataGrid
Type: Bug Report
1
DataGrid: IndexOutOfRangeException is thrown when updating the ItemsSource after calling its Clear method

IndexOutOfRangeException occurs in some situations when updating the ItemsSource collection of RadDataGrid. In order to reproduce the issue, the ItemsSource collection should be cleared by calling its Clear method. When you add a specific number of items after that the error occurs. The number of added items depends on the viewport's height.

To work this around, instead of calling the Clear() method of the ItemsSource collection, remove the items one by one.

var collection = (ObservableCollection<MyModel>)this.dg.ItemsSource;
 while (collection.Count > 0)
 {
     collection.RemoveAt(collection.Count - 1);
 }

 

0 comments