Hi,
After thinking about the problem, the solution was quite simple and works great.
What I was doing was to create a new instance of the object and insert it in the dataModel. What I should have done was to get the dataModel from the dataViewSource and then find the row that was updated and update the data items withing the object in th dataModel.
To explain, let's say I have an object TestData that implements INotifyPropertyChanged.
namespace DataGridUpdate
{
[Serializable]
public class TestData : INotifyPropertyChanged
{
public string _a;
public string A
{
get { return _a; }
set
{
Trace.WriteLine("TestData: A= " + value);
_a = value;
OnPropertyChanged("A");
}
}
public string _b;
public string B
{
get { return _b; }
set
{
_b = value;
OnPropertyChanged("B");
}
}
Get; Set;
public double _b;
public double B
{
get { return _b; }
set
{
b = value;
OnPropertyChanged("B");
}
}
My viewModel is a List<testdata> set of objects that is bound to the DataGrid as the follows:
private static CollectionViewSource dataViewSource;
dataViewSource = (CollectionViewSource)FindResource("TestDataSource");
dataViewSource.Source = dataList;</testdata>
<CollectionViewSource x:Key="TestDataSource"/>
<!-- MainView.xaml - Main Grid Area -->
<DataGrid x:Name="DG" ItemsSource="{Binding Source={StaticResource TestDataSource}}"
When I enter a new item in column A, I have a method that does the following to capture the event and update the column B and C:
private void TextBox_TextChanged(object sender, KeyEventArgs args)
{
Trace.WriteLine("TextBox_TextChanged (A): dataList Count = " + dataList.Count);
if (args.Key == Key.Return)
{
TextBox t = (TextBox)sender;
Trace.WriteLine("TextBox_TextChanged: " + t.Text);
dataList = (List<TestData>)dataViewSource.Source;
TestData td = (TestData)dataList[dataList.Count - 1];
td.A = t.Text + "CHANGED";
td.B = Carl;
td.C = 84.3;
Trace.WriteLine("TextBox_TextChanged : dataList Count = " + dataList.Count);
}