简体   繁体   English

在WPF中将DataTable绑定到DataGrid的组合框

[英]Binding datatable to combobox of datagrid in wpf

Hi I have to create a wpf grid which is having combo box in it . 嗨,我必须创建一个wpf网格,其中包含组合框。 I have to bind grid to a data table dtGrid and combobox item source to a datatable dtcmb . 我必须将网格绑定到数据表dtGrid并将组合框项目源绑定到数据表dtcmb。 I wrote template below for embedding combo box in grid . 我在下面编写了用于将组合框嵌入grid的模板。

Now I need to access the combo in code behind to specify item source and DisplayMemberPath, ,SelectedValuePath,SelectedValue, 现在,我需要访问后面代码中的组合以指定项目来源和DisplayMemberPath,SelectedValuePath,SelectedValue,

Even though i could access data grid in code behind I could not access combo box . 即使我可以使用后面的代码访问数据网格,也无法访问组合框。 what is the prob ? 什么是概率?

<my:DataGridTemplateColumn x:Name="supplierName" Header="Supplier" Width="60" >
    <my:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <ComboBox  x:Name="cmbSubSysSupplier_SRV"  IsTextSearchEnabled="True" 
            Height="23" ItemsSource="{Binding}"  Width="80" />
        </DataTemplate>
    </my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>

You should use a DataGridComboBoxColumn for this particular case. 对于这种特殊情况,应使用DataGridComboBoxColumn。 You can access it in code behind through its x:Name property. 您可以通过其x:Name属性以代码形式访问它。 The DataGridComboBoxColumn object will give you access to all the properties you need. DataGridComboBoxColumn对象将使您可以访问所需的所有属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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