I am writing CRUD code for WPat Datagrid.
In TheDataGrid_CellEditEnding method below:
- How to get the source text before the user made the changes?
- I need the source code to be able to modify the client and save it back to the database using _db.SubmitChanges ()
Here's a complete solution with a database if someone wants to experiment with this:
http://www.tanguay.info/web/download/testDataGrid566northwindDatagrid.zip
XAML:
<toolkit:DataGrid x:Name="TheDataGrid"
AutoGenerateColumns="True"
CellEditEnding="TheDataGrid_CellEditEnding"/>
background code:
private void TheDataGrid_CellEditEnding(object sender, Microsoft.Windows.Controls.DataGridCellEditEndingEventArgs e)
{
Customer customer = e.Row.Item as Customer;
string customerID = customer.CustomerID;
int displayIndex = (int)e.Column.DisplayIndex;
string originalText = customer.Fields[displayIndex].value.ToString();
TextBox changedTextBox = e.EditingElement as TextBox;
string changedText = changedTextBox.Text;
Message.Text = String.Format("cell was changed from {0} to {1}", originalText, changedText);
_db.SubmitChanges();
}
source
share