简体   繁体   中英

Binding datatable to combobox of datagrid in wpf

Hi I have to create a wpf grid which is having combo box in it . I have to bind grid to a data table dtGrid and combobox item source to a datatable dtcmb . I wrote template below for embedding combo box in grid .

Now I need to access the combo in code behind to specify item source and 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. You can access it in code behind through its x:Name property. The DataGridComboBoxColumn object will give you access to all the properties you need.

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