简体   繁体   中英

codebehind binding of DataGridComboboxColumn in wpf datagrid

How do do this binding in Code behind:

<Grid >
    <Grid.Resources>
        <ObjectDataProvider x:Key="ProductDataProvider" ObjectType="{x:Type local:clsPurchaseOrderList}" MethodName="GetProducts" />
    </Grid.Resources>

where my datagrid is as :

<my:DataGrid Name="dgvPurchaseOrder"
                             ItemsSource="{Binding}" 
                             SelectionUnit="CellOrRowHeader"
                             TabIndex="3">
                    <my:DataGrid.Columns>

                        <my:DataGridComboBoxColumn 
                                       Width="100"
                                       Header="Product Code"
                                       SelectedValueBinding="{Binding Path=Product_Id,UpdateSourceTrigger=PropertyChanged}"                                                                                       
                                       SelectedValuePath="Product_Id"
                                       DisplayMemberPath="Product_Code"                                           
                                       ItemsSource="{Binding Source={StaticResource ProductDataProvider}}">
                            <my:DataGridComboBoxColumn.EditingElementStyle>
                                <Style TargetType="ComboBox">
                                    <Setter Property="IsEditable" Value="True" />
                                </Style>
                            </my:DataGridComboBoxColumn.EditingElementStyle>
                        </my:DataGridComboBoxColumn>
                                   .
                                   .
                                   .
                    </my:DataGrid.Columns>
                </my:DataGrid>
</Grid>

I want to bind the datagridComboboxColumn in codebehind how to accomplish this

try something like:

((DataGridComboBoxColumn)PaymentDistributionDataGrid.Columns[1]).ItemsSource = taskGetMortgageInterfaceInformation.Result.TransactionCodes.Where( x => !x.Description.Equals("@"));
                   ((DataGridComboBoxColumn)PaymentDistributionDataGrid.Columns[1]).SelectedValuePath = "Code";
                   ((DataGridComboBoxColumn)PaymentDistributionDataGrid.Columns[1]).SelectedValueBinding = new Binding("MITransactionCode");
                   ((DataGridComboBoxColumn)PaymentDistributionDataGrid.Columns[1]).DisplayMemberPath = "Code";   

Where PaymentDistribution is my editable datagrid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM