Custom collection crashes DataGrid on Edit

微笑、不失礼 提交于 2019-12-06 01:27:12

问题


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:


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



来源:https://stackoverflow.com/questions/5181519/custom-collection-crashes-datagrid-on-edit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!