Is there some way to get the final value of an edited cell in datagrid in the view model? #7314
Replies: 4 comments
-
Technically the properties of the item can be changed from anywhere, so in general it doesn't make much sense to monitor the one who is changing it rather than the item, unless you want to customize that process. There is a few hacks, waiting for the binding operations to complete, or getting the TextBox instance that should have the value. You can also have the item call you instead of subscribing to its changes from outside. |
Beta Was this translation helpful? Give feedback.
-
Thanks so much for your comments. Could you share some code how to do it? For example the solution in which last one, have the item call instead of subscribe to the events. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Do you have the code somewhere or describe the design a bit? One way to do this is to have your own collection type, with the items holding reference to the "owner". The item could then inform the collection that it has been changed. Would such approach work for you? |
Beta Was this translation helpful? Give feedback.
-
Finally, I have to decide to exetend the observable collection to create a new one that add some features. This allows me to use this observable collection when I need and not duplicate code. The features are;: 1.- I have added two methods, AddRange and RemoveRange. This is the code:
Thanks. |
Beta Was this translation helpful? Give feedback.
-
I have a datagrid that binds to a collection in my view model.
The user can edit a cell that is a decimal and bind to a decimal porperty of the item source.
I would like to know, when the user press the return key or the cell loses the focus, to fire a command in my model to update the item in the database.
The problem is that the events that has the datagrid is ending editing, so it is before the new value is commited.
I know that I could subscribe to the event of notify property of the item source, so when the property is changed, I would have the new value and I could do what I need. But really it makes me to subscribe and unsubscribe to the event every time I update the collection.
Isn't there a better solution? Why there is not an event that it could be CellEndEdit and not only CellEndingEdit?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions