Question

I have a datagrid with an Observable Collection of a custom object. The selectedItem binding is set to SelectedCustObject in my view model. I've wired up a property Changed handler so I can update the database anytime the user makes a change to the selectedItem. When the property is updated my Save() sub fires and passes the Custom Object ByRef to my middle layer (WCF) and returns it. The datagrid loses it's SelectedItem state at this point. I'm not sure if I'm going about this right or if there is a better way.

SelectedItem="{Binding Path=SelectedMeterUsage, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Was it helpful?

Solution

It sounds as if the reference SelectedMeterUsage is changing, and no longer pointing to the same instance that is in your ObservableCollection, therefore the grid no longer knows which item is selected. You will either need to change your update code to not change the reference, or after the save, you would need to reset the reference by finding the item in the ObservableCollection with the same ID and assigning it to SelectedMeterUsage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top