Updating data in datagrid
Once the Framework Element is extracted, by type casting it to the ‘Text Box’ UI element, the value changed in the cell can be read.
Here ‘Salary’ and ‘Dept No’ are changed and updated into the selected ‘Employee’ object.
Abstract: I was recently working on a requirement to perform Update and Delete operations on a WPF Data Grid control (similar to what developers do in a ASP. The WPF Data Grid is an excellent control to bind with collections and provides various events to work with. Now since Salary and Dept No can be updated, on the click event of the ‘Update’ button, the following code is written.
The Template column generates buttons for all rows, which will add buttons for the last row where no data is present.
So the ‘if’ statement in the above code, will prevent the application from crashing, since the WPF Data Grid generates a blank row when the data is bound to it.