簡體   English   中英

WPF DataGrid中DataGridComboboxColumn的代碼隱藏綁定

[英]codebehind binding of DataGridComboboxColumn in wpf datagrid

如何在后面的代碼中進行此綁定:

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

我的數據網格在哪里:

<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>

我想在代碼背后綁定datagridComboboxColumn如何完成此操作

嘗試類似:

((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";   

其中PaymentDistribution是我的可編輯數據網格。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM