Mussammil
Mussammil

Reputation: 894

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

Upvotes: 0

Views: 1247

Answers (1)

yashashwi
yashashwi

Reputation: 50

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.

Upvotes: 1

Related Questions