0

我想创建一个窗口,让我可以插入一个包含尽可能多的联系人的公司。我看起来像这样的表之间的关系:http: //imgur.com/xP2M49k

这是我的窗口的 XAML(省略了 Grid 和其他一些不必要的细节):

        <Label Grid.Row="0" Grid.Column="0" Margin="3 3 3 3">Firmenname</Label>
    <TextBox x:Name="UiCompanyNameTextBox" Grid.Row="0" Grid.Column="1" Margin="3 3 3 3" Text="{Binding Path=CompanyName}"/>

    <Label Grid.Row="0" Grid.Column="3" Margin="3 3 3 3">Branche</Label>
    <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}"/>

    <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">
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding Path=Company}" Visibility="Collapsed"></DataGridTextColumn>
            <DataGridComboBoxColumn x:Name="UiPersonDataGridComboBoxColumn" Header="Kontaktperson" DisplayMemberPath="Forename" 
                                    SelectedValuePath="id" SelectedValueBinding="{Binding Path=Person}"/>
            <DataGridComboBoxColumn x:Name="UiPositionDataGridComboBoxColumn" Header="Position" DisplayMemberPath="Position" 
                                    SelectedValuePath="id" SelectedValueBinding="{Binding Path=Position}"/>
        </DataGrid.Columns>
    </DataGrid>

这是我背后的代码:

    公共部分类 AddCompany :窗口
        {
            私有DataRowView公司DataRowView;
            private ClientManager.ClientManagerDataSet.ContactPersonDataTable contactPersonDataTable;

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(); } }

该公司的插入工作。但是,我无法绑定 Datagrid,以便它使用新公司的 Company-Id 插入行。通常我会通过事务来执行此操作,但由于使用了 DataSet,我认为这必须以某种方式实现?

4

0 回答 0