title: DataTable Relation problem with Datagrid (wpf)
body: <p>I've got a problem that is driving me insane.</p>
  
  <p>I created a DataSet with DataRelations and I want it to be displayed in a parent/child manner.  </p>
  
  <p>To make it easy I only have 2 tables:  </p>
  
  <ol>
  <li>test with id (int)(PK), col1 (string)</li>
  <li>test1 with id(int)(PK)(FK -> test>id), col1 (string)  </li>
  </ol>
  
  <p>I created a relation between test and test2 like this:  </p>
  
  <pre><code>DataRelation rel = new DataRelation("testRel",  
  new DataColumn[] { database1DataSet.test.IDColumn },  
  new DataColumn[] { database1DataSet.test1.idColumn });
  </code></pre>
  
  <p>I set the DataContext of the Grid containing my two Datagrids to  </p>
  
  <pre><code>&lt;Grid DataContext="{Binding Source={StaticResource database1DataSet}, Path=test}"&gt; 
  </code></pre>
  
  <p>then I created two DataGrids. The first one:  </p>
  
  <pre><code>&lt;DataGrid IsSynchronizedWithCurrentItem="True" Name="dataGrid1" ItemsSource="{Binding}"&gt; 
  </code></pre>
  
  <p>The second one:  </p>
  
  <pre><code>&lt;DataGrid IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=testRel}" Name="dataGrid2"&gt;  
  </code></pre>
  
  <p>The Columns are of course bound to the proper ColumnIDs.  </p>
  
  <p>You can cycle to the parent grid and the child grids elements change, just like I wanted it to do.  </p>
  
  <p>When you add a new row to the child grid (via NewItemPlaceholder) it auto completes the relation value, in this case the id value in test1 is taken from the selected parent row (column id of test), just like you'd expect it to work.  </p>
  
  <p>Now if you add a new row to the MASTER grid by filling out the NewItemPlaceholder and submitting it by pressing  "Enter" the item is created in the master grid and is commited to the database as well. But if you try to add child row for this, newly added, master row the weird behaviour takes place.  </p>
  
  <p>You click on the NewItemPlaceholder in the child datagrid. The first thing to notice is, that there won't be the auto completion of the id-value like when doing this for already existing rows. The second one is, that the row dissapears immediately after pressing enter from the second grid. You can't even make it visible again by cycling through the parent grid. (The row in the dataset though). If you rerun the application the newly added rows appear and work like intended.</p>
  
  <p>If you add a new row programmatically with  </p>
  
  <pre><code>database1DataSet.test.AddtestRow(4, "asd");  
  </code></pre>
  
  <p>the werid behaviour won't take place.</p>
  
  <p>The question is: why is adding a new row to the datatable via datagrid different from doing it programmatically and how can I fix it/build a nice workaround?</p>
  
  <p>Thanks in advance</p>
  
  <p>P.S. if you need the Code you can download it at 
  <a href="https://rapidshare.com/files/2456035623/WpfApplication1.zip" rel="nofollow">https://rapidshare.com/files/2456035623/WpfApplication1.zip</a> (VS2010 Solution)</p>