In Synfusion SfDataGrid, I want to replace the ItemsSource during runtime with a new collection. my ItemsSource is an ObservableCollection which I have already implemented the INotifyPropertyChanged requirements for it. The definition of my Collection is as follow:
public ObservableCollection<JxTask> Tasks
{
get
{
if (_tasks == null)
{
_tasks = MainModel.GetIssues();
}
return _tasks;
}
set
{
if (_tasks != value)
{
_tasks = value;
OnPropertyChanged("Tasks");
}
}
}
Drop event function is defined as follow:
private void RowDragDropController_OnRowDropped(object sender, GridRowDroppedEventArgs e)
{
ObservableCollection<JxTask> aktuelleissues = MainModel.GetIssues();
ObservableCollection<JxTask> alteIssues = sfDataGrid.ItemsSource as ObservableCollection<JxTask>;
if (alteIssues != null && aktuelleissues != null)
{
foreach (var item in alteIssues)
{
item.sortOrder = (from x in aktuelleissues where x.id == item.id select x).FirstOrDefault().sortOrder;
}
}
if (aktuelleissues != null)
{
sfDataGrid.ItemsSource = aktuelleissues;
}
CollectionViewSource.GetDefaultView(sfDataGrid.ItemsSource).Refresh();
}
everything works fine after first drop (grid will get updated with new collection) but as soon as trying to drag another item, i rises **System.NullReferenceException: 'Object reference not set to an instance of an object.'**
Any advice what may cause this?