Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In Grid Resource am using
DataTemplate 
with 2 combobox to shown workweek and year, I tried bind data in
combobox 
but its not working , Please help me resolve this problem.

I tried combobox.content in cs file, there is no option to use combobox in cs.file
Not able to bind data in DataTemplate --
combobox wpf c#


What I have tried:

<Grid.Resources>
            <!--DataTemplate for Published Date column defined in Grid.Resources.  PublishDate is a property on the ItemsSource of type DateTime -->
            <DataTemplate x:Key="DateTemplateAlpha" >
                <StackPanel Width="100" Height="auto" Orientation="Horizontal">
                    <ComboBox  Name="cmbAlphaYear" HorizontalAlignment="Left" VerticalAlignment="Top" Width="50" Height="18" FontSize ="15"
                      Background="FloralWhite" Text="Select Year" 
                   ItemsSource="{Binding Path=DataContext.YearList, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" DisplayMemberPath="Year" SelectedValuePath="Year"/>

                    <ComboBox  Name="cmbAlphaWW" HorizontalAlignment="Left" VerticalAlignment="Top" Width="50" Height="18" FontSize ="15"
                      Background="FloralWhite" Text="Select WorkWeek"
                    DisplayMemberPath="skuName" SelectedValuePath="skuId"/>
                </StackPanel>
            </DataTemplate>
</Grid.Resources>



<datagrid x:name="dgData" autogeneratecolumns="False" margin="58,124,64,40" canuseraddrows="False">
<datagrid.columns>
<datagridtextcolumn header="Config" binding="{Binding Config}" isreadonly="True" width="*">
<datagridtemplatecolumn header="Alpha" x:name="Alpha" celltemplate="{StaticResource DateTemplateAlpha}" width="100">
<datagridtemplatecolumn header="Beta" x:name="Beta" celltemplate="{StaticResource DateTemplateBeta}" width="100">
<datagridtemplatecolumn header="PV" x:name="PV" celltemplate="{StaticResource DateTemplatePv}" width="100">
Posted
Updated 16-Jun-20 0:35am
Comments
Maciej Los 16-Jun-20 6:02am    
Do not use grid. Use StackPanel.

1 solution

As i mentioned in the comment to the question, i'd suggest to use StackPanel. Here is simple implementation: Dynamic ComboBox from Data Source[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900