开发者

Editing ObservableDictionary via DataGrid

I binded my ObservableDictionary to a DataGrid.ItemSource . My problem is when i try to edit a value via the datagrid. I get the exception "开发者_如何学GoEdititem is not allowed for this view". I've tried different solutions - such as binding the ObservableDictionary.Values.ToList to the datagrid - which makes it possible to edit items but the original value collection is no longer binded.

So, how do I bind ObservableDictionary to a DataGrid and i still keep it editable. Thank you very much!


While trying to do basically the same thing recently, I've came upon ObservableKeyedCollection. It requires the key to be stored within the item class (which, by the way, is the source of trouble with ObservableDictionary - it uses KeyValuePair<> struct for enumeration, and that struct isn't editable), but works together with DataGrid, allowing it to edit the items.


You may find the following helpful:

Working with editing commands Default commands have been added to the DataGrid to support editing. These commands and their default input bindings are:

  • · BeginEditCommand (F2) ·

  • CancelEditCommand (Esc) ·

  • CommitEditCommand (Enter) ·

  • DeleteCommand (Delete)

The whole blog post is here: http://blogs.msdn.com/b/vinsibal/archive/2008/10/01/overview-of-the-editing-features-in-the-wpf-datagrid.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜