将数据从DataGrid工具包中读取到表

时间:2019-01-21 13:58:42

标签: c datagrid wpftoolkit

有一个带有组合框的动态可填充数据网格。数据取自不同表的ObservableCollection。接下来,必须将具有值的已填充DataGrid写入sql server数据库中的另一个表。请告诉我如何执行? XML:

<Grid Margin="10,10,-8,0" Width="Auto" Height="Auto">
    <Grid.Resources>
        <ObjectDataProvider x:Key="categoriesDataProvider" ObjectType="{x:Type local:Categories}" MethodName="GetCategories"/>
    </Grid.Resources>
    <dg:DataGrid x:Name="pr_list" AutoGenerateColumns="False" HorizontalAlignment="Left" VerticalAlignment="Top" Height="154" Width="490" RowBackground="White" AlternatingRowBackground="LightGray" Margin="81,168,0,0">
        <dg:DataGrid.Columns>
            <dg:DataGridComboBoxColumn Header="Категория" Width="150"
                 SelectedValueBinding="{Binding Path=CurrentCategory}"                                                                                       
                 SelectedValuePath="id"
                 DisplayMemberPath="description"                                           
                 ItemsSource="{Binding Source={StaticResource categoriesDataProvider}}">
                <dg:DataGridComboBoxColumn.EditingElementStyle>
                    <Style TargetType="ComboBox">
                        <Setter Property="IsEditable" Value="False"/>
                    </Style>
                </dg:DataGridComboBoxColumn.EditingElementStyle>
            </dg:DataGridComboBoxColumn>
            <dg:DataGridComboBoxColumn Header="Товар" Width="200"
                   SelectedValueBinding="{Binding Path=CurrentProduct}"                                                                                       
                   SelectedValuePath="id"
                   DisplayMemberPath="p_name">
                <dg:DataGridComboBoxColumn.ElementStyle>
                    <Style TargetType="ComboBox">
                        <Setter Property="ItemsSource" Value="{Binding Path=ProductsInCategory}"/>
                    </Style>
                </dg:DataGridComboBoxColumn.ElementStyle>
                <dg:DataGridComboBoxColumn.EditingElementStyle>
                    <Style TargetType="ComboBox">
                        <Setter Property="ItemsSource" Value="{Binding Path=ProductsInCategory}"/>
                        <Setter Property="IsEditable" Value="False"/>
                    </Style>
                </dg:DataGridComboBoxColumn.EditingElementStyle>
            </dg:DataGridComboBoxColumn>
            <dg:DataGridComboBoxColumn Header="Ед.изм."  Width="50"
                                       SelectedValueBinding="{Binding Path=CurrentUnit}"                                                                                       
                                       SelectedValuePath="id"
                                       DisplayMemberPath="unit">
                <dg:DataGridComboBoxColumn.ElementStyle>
                    <Style TargetType="ComboBox">
                        <Setter Property="ItemsSource" Value="{Binding Path=UnitInProducts}" />
                    </Style>
                </dg:DataGridComboBoxColumn.ElementStyle>
                <dg:DataGridComboBoxColumn.EditingElementStyle>
                    <Style TargetType="ComboBox">
                        <Setter Property="ItemsSource" Value="{Binding Path=UnitInProducts}" />
                        <Setter Property="IsEditable" Value="False" />
                    </Style>
                </dg:DataGridComboBoxColumn.EditingElementStyle>
            </dg:DataGridComboBoxColumn>
            <dg:DataGridTextColumn Header="Кол-во" Width="80">
                <dg:DataGridTextColumn.ElementStyle>
                    <Style TargetType="TextBlock">

Этопривязка:

private void FillComboGroup() 
    {
        pr_list.ItemsSource = new ObservableCollection<ProductCategory>();
    }

0 个答案:

没有答案