Custom collection crashes DataGrid on Edit

1.8k views Asked by At

Im currently trying to bind the DataGrid.ItemsSource to a custom RowCollection, which implements IList and INotifyCollectionChanged:

Public Class RowCollection(of T)
Implements IList(Of T)
Implements INotifyCollectionChanged
Private _List As New List(Of T)
...

(Sorry for the VB code, I'll be translating all my code to C# soon.)

Notice the class does not derive from any existing CLR collection. I created my own class because I need to override GetItemAt, in order to implement record paging. The Collection Internally adds and removes objects from its own private List _List.

Now, I am able to view the items in a DataGrid, but as soon as I double click a cell to edit, I recieve an InvalidOperationException: 'EditItems' is not available..

My question is, what other interfaces should I implement in order to make my collection fully compatible with DataGrid?

1

There are 1 answers

0
Vincent Vancalbergh On BEST ANSWER

Here you can read the following:

Editing

By default, you can edit items directly in the DataGrid. To guarantee that edits can be committed and canceled correctly, the objects in the DataGrid must implement the IEditableObject interface. Alternatively, you can set the IsReadOnly property to true to disable editing in the DataGrid.

The IEditableObject interface is here Also see IEditableCollectionView here