Hancs
Hancs

Reputation: 333

WPF Datagrid 'CurrentItem' property not taking updated values from datagrid

hope you are well!

Youtube video of my problem

As you can see in the short video (49 seconds), when I change a value in the datagrid and click the update button the datagrid.CurrentItem doesn't have the changed value but when I update it for the second time and I first click outside the datagrid row and then click the update button it works... I have tried an observable collection (a colleague suggested, but I have never worked with them before and as far as I can see it made no difference. The collection didn't even update.)

Thanks for taking the time to help!

Upvotes: 0

Views: 464

Answers (1)

DonBoitnott
DonBoitnott

Reputation: 11035

Classic "edit mode" problem. In the first take, the cell is in "edit mode", and has not yet committed the value to the row. In the second take, you click off, allowing the cell's editor to validate and commit. That's the only difference.

So, if you want to be able to support the first behavior, you need to add a line to the button click handler to validate the row.

Something like this, perhaps:

rowBeingEdited.EndEdit();

I don't think an ObservableCollection would solve anything, because it is not a data store problem, it is a problem with the editor not realizing that you are done with the edit.

Upvotes: 1

Related Questions