Hi All!
In my program I use a DataGrid behaviour dicussed in this thread:
It works quite fine. I have one problem. If I edit the new row and I leave the DataGrid, but the screen remains visible (or the DataGrid is hided), the edited new row disappears by Cancelling edition, but no new placeholder row appears instead. I would like the new empty row to appear right after Cancelling.
Here you can find a simple program with the described problem.
If you just have an idea, please share it with me!
Csaba
Csaba CzinePosted May 9, 2011, 12:46 PM
I have just realized that the linked thread is no longer available.
The behaviour in my program solves the following issue:
If I leave the Data view without finishing the edition of a row, and later I come back, the DataGrid thorws an InvalidOperationException, with the following message:
'DeferRefresh' is not allowed during an AddNew or EditItem transaction.
This is handled by the added behaviour by adding eventhandlers to the DataGrid to the LostKeyboardFocus and the DataContextChanged events, which cancel pending changes. It works, but in case of new item placeholder cancelling edition removes the placeholder as well from the datagrid, and it appears again only if I reload the Data view into the ContentPresenter. I don't want to put the user into such circumstances. :)
The collection.AddNew(); is not good, because it creates a new element, but it is not a placeholder. Furtheremore it is added in an editing state, so it throws the above exception when leaving and redisplaying the view.
Thanks for your answer, anyway! It made me think it over again and perhaps a new event in an inheriting calss could handle the situation. I will try it, but I am still interested in other, better solutions.
I uploaded my example program with this post again. The other palce was temporary.
Amit ChoudharyPosted May 9, 2011, 2:12 AM
Remove this line
my_place:DataGridBehaviour.DataGridRollbackOnUnfocused="True"
and your placeholder will remain there..
if (collection.IsAddingNew)
{
collection.CancelNew();
collection.AddNew();
}
your panel will remain visible with rollback.