Hi
I can successfully create a list of ExpandoObjects then create an ObservableCollection to wrap these, and then bind to this.
However if I first create the ObservableCollection, then add ExpandoObjects to this I get ArgumentOutOfRangeException, stack trace:
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at Syncfusion.Data.EnumerableRecordsWrapper.get_Item(Int32 index)
at Syncfusion.UI.Xaml.Grid.SfDataGrid.GenerateGridColumnsForDynamic(Columns columns, ICollectionViewAdv view)
at Syncfusion.UI.Xaml.Grid.SfDataGrid.GenerateGridColumns(Columns columns, ICollectionViewAdv view)
at Syncfusion.UI.Xaml.Grid.SfDataGrid.GenerateGridColumns()
at Syncfusion.UI.Xaml.Grid.GridModel.OnViewPropertyChanged(Object sender, PropertyChangedEventArgs e)
at Syncfusion.Data.CollectionViewAdv.RaisePropertyChanged(String propertyName)
at Syncfusion.Data.CollectionViewAdv.SetItemProperties(IEnumerable dataSource)
at Syncfusion.Data.CollectionViewAdv.SourceNotifyCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at CallSite.Target(Closure , CallSite , ObservableCollection`1 , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
at Profound.Mining.ViewModel.Foundation.Sub.DataInputGridViewModel.ExecuteSFDynamicCommand() in v:\Profound.Mining.Base\Profound.Mining.ViewModel.Foundation\Sub\DataInputGridViewModel.cs:line 188
ScenarioMy sfDataGrid is binding to a property on my ViewModel with the attribute ItemsSource="{Binding GridData}
my ViewModel GridData property is typed:
public ObservableCollection<Object> GridData (implements INPC)
Code that works (create list of ExpandoObject, then create ObservableCollection from it) dynamic newRow;
var data = new List<Object>();
newRow = new ExpandoObject();
newRow.Name = "Chickens";
newRow.When = new DateTime(2014, 1, 1);
newRow.HowMany = 4;
data.Add(newRow);
newRow = new ExpandoObject();
newRow.Name = "Geese";
newRow.When = new DateTime(2014, 6, 14);
newRow.HowMany = 2;
data.Add(newRow);
newRow = new ExpandoObject();
newRow.Name = "Swans";
newRow.When = new DateTime(2015, 2, 14);
newRow.HowMany = 3;
data.Add(newRow);
GridData = new ObservableCollection<object>(data);
Code that does not work (create ObservableCollection first, then add rows directly to it) dynamic newRow;
GridData = new ObservableCollection<object>();
newRow = new ExpandoObject();
newRow.Name = "Chickens";
newRow.When = new DateTime(2014, 1, 1);
newRow.HowMany = 4;
GridData.Add(newRow); //ArgumentOutOfRangeException on this line
newRow = new ExpandoObject();
newRow.Name = "Geese";
newRow.When = new DateTime(2014, 6, 14);
newRow.HowMany = 2;
GridData.Add(newRow);
newRow = new ExpandoObject();
newRow.Name = "Swans";
newRow.When = new DateTime(2015, 2, 14);
newRow.HowMany = 3;
GridData.Add(newRow);
I have seen other threads on using dynamic/ExpandoObject data for sfDataGrid and these suggest you have added support for these.
Thanks
Steve