0
votes

I have a parent form with a customers listing in a WPF datagrid.

Editing a line of the form is done in a child form: click on a button in a line, open child form using selected item of datagrid and assign it to child form datacontext.

When a PropertyChanged event is triggered in the child form, the line being edited in the parent form listing updates.

If I decide to cancel my current modification by clicking on a cancel button in child form, I restore the original values ​​of the edited customer: before editing I made a clone of to be edited customer. Then now I reset child form DataContext by setting it to null then to the cloned customer. This was the hack I read on SO about forcing DataContext to refresh with DataContext itself being changed, not properties on its objects.

After canceling edit, child form shows the values I expect (properties of cloned customer), while the associated line in parent form listing didn't update: still shows edited customer values.

How can I ask parent form to update itself? I'm afraid I lost some references between objects by reassigning child form datacontext to a new object (loosing link to parent form datagrid interesting line selected item).

Thanks for your guidance,

EDIT : When I am ready to edit a customer in child form, I assign datagrid selected item to a static variable of my application since it's mono-user, so that it's easier to handle "current customer". When I cancel edition, this static variable value has changed, but maybe I have to assign it to parent form datagrid selected item back too?

1

1 Answers

0
votes

I was right: after child form closes, I must update parent form datagrid collection, at right index, with updated object.

// update static variable
SocodifApp.Client = ((Client) Listing.SelectedItem);            
ClientForm editClientForm = new ClientForm();
editClientForm.ShowDialog();
// Get modified static variable after child form closes and update datagrid collection    
// relevant item
_dataContainer.Clients[Listing.SelectedIndex] = SocodifApp.Client;