Gu.Wpf.DataGrid2D icon indicating copy to clipboard operation
Gu.Wpf.DataGrid2D copied to clipboard

Insert to ObservableCollection<ObservableCollection<T>> set as RowSource throws

Open martinskuta opened this issue 6 years ago • 1 comments

Hey,

started playing around with your extensions as I am building simple table designer control in WPF and your library is a good kickstarter as we can use really tabular items source (collection of collections). Really cool, thank you for that!

I was working on a POC where I was implementing drag/drop reorder of columns and rows and realized that your extension has a bug when inserting a row to different index than the last index (simple add). If you insert a row to the ObservableCollection bound as RowSource to index 0, ListCollectionView will throw InvalidOperationException.

You can reproduce it easily in your Demo project by changing this line to this.Data.Insert(0, new ObservableCollection<int>(newRow)); instead of Add and then on second call it will fail.

The exception is thrown because the List2DView doesn't actually insert the row internally, but adds it to the end. I had a quick look and the root cause is this line where you should call this.Rows.Insert(index, listRowView); instead of this.Rows.Add(listRowView);. I think the fix will be bit more difficult, because indexes of ListRowViews following the insertion need to be updated, which is not possible at the moment as they are only readonly properties and also the property list index descriptors I believe, so it seems also like architectural change.

Do you see a simple way of fixing it?

martinskuta avatar Jun 25 '18 22:06 martinskuta

Thanks for reporting! I'll have a look, the internals are a bit messy here.

JohanLarsson avatar Jun 26 '18 05:06 JohanLarsson