title: wpf: Inserting into related rows using DataSet
body: <p>I want to create a Window that lets me insert a Company with as many contactpersons I want. The relation between the tables I look like this:
  <a href="http://imgur.com/xP2M49k" rel="nofollow">http://imgur.com/xP2M49k</a></p>
  
  <p>This is the XAML for my window (the Grid and some other unnecessary details are omitted):</p>
  
  <pre><code>        &lt;Label Grid.Row="0" Grid.Column="0" Margin="3 3 3 3"&gt;Firmenname&lt;/Label&gt;
      &lt;TextBox x:Name="UiCompanyNameTextBox" Grid.Row="0" Grid.Column="1" Margin="3 3 3 3" Text="{Binding Path=CompanyName}"/&gt;
  
      &lt;Label Grid.Row="0" Grid.Column="3" Margin="3 3 3 3"&gt;Branche&lt;/Label&gt;
      &lt;ComboBox x:Name="UiBranchComboBox" Grid.Row="0" Grid.Column="4" Margin="3 3 3 3" ItemsSource="{Binding}" DisplayMemberPath="BranchName" 
                SelectedValuePath="id" SelectedValue="{Binding Path=Branch}"/&gt;
  
      &lt;DataGrid x:Name="UiContactPersonDataGrid" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="5" CanUserAddRows="True" CanUserDeleteRows="True" 
                Margin="3 3 3 3" ItemsSource="{Binding}" AutoGenerateColumns="False"&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridTextColumn Binding="{Binding Path=Company}" Visibility="Collapsed"&gt;&lt;/DataGridTextColumn&gt;
              &lt;DataGridComboBoxColumn x:Name="UiPersonDataGridComboBoxColumn" Header="Kontaktperson" DisplayMemberPath="Forename" 
                                      SelectedValuePath="id" SelectedValueBinding="{Binding Path=Person}"/&gt;
              &lt;DataGridComboBoxColumn x:Name="UiPositionDataGridComboBoxColumn" Header="Position" DisplayMemberPath="Position" 
                                      SelectedValuePath="id" SelectedValueBinding="{Binding Path=Position}"/&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  </code></pre>
  
  <p>This is my code behind:
  <pre>
      public partial class AddCompany : Window
          {
              private DataRowView companyDataRowView;
              private ClientManager.ClientManagerDataSet.ContactPersonDataTable contactPersonDataTable;</p>
  
  <code>        public AddCompany()
          {
              InitializeComponent();
          }
  
          private void Window_Loaded(object sender, RoutedEventArgs e)
          {
              UiBranchComboBox.ItemsSource = DataSetManager.BranchTA.GetData();
  
              ClientManagerDataSet.CompanyDataTable companyDataTable = DataSetManager.CompanyTA.GetData();
              companyDataRowView = companyDataTable.DefaultView.AddNew();
              UiGrid.DataContext = companyDataRowView;
              companyDataRowView.BeginEdit();
  
              contactPersonDataTable = new ClientManager.ClientManagerDataSet.ContactPersonDataTable();
              DataView dv = contactPersonDataTable.DefaultView;
              UiContactPersonDataGrid.DataContext = contactPersonDataTable;
  
              UiPersonDataGridComboBoxColumn.ItemsSource = DataSetManager.PersonTA.GetData();
              UiPositionDataGridComboBoxColumn.ItemsSource = DataSetManager.PositionTA.GetData();
          }
  
          private void UiApplyButton_Click(object sender, RoutedEventArgs e)
          {
              companyDataRowView.EndEdit();
              DataSetManager.CompanyTA.Update(companyDataRowView.Row);
              DataSetManager.ContactPersonTA.Update(contactPersonDataTable);
              this.Close();
          }
      }
  </code></pre>
  
  <p>
  The insertion of the company works. However, I am not able to bind the Datagrid so that it inserts the rows with the Company-Id of the new Company. 
  Normally I would do this with a transaction, but since a DataSet is used I figured this must be possible somehow?</p>