Click here to Skip to main content
15,882,954 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
want to include listbox in wpf datagrid control when datgrid click the cell, as like as outlook calander.

My Xaml Code


C#
<DataGrid Name="Grid1" Height="550" Width="850" AutoGenerateColumns="False" CanUserResizeRows="False" CanUserDeleteRows="False" CanUserAddRows="False" AreRowDetailsFrozen="False" SelectionUnit="CellOrRowHeader" SelectedCellsChanged="Grid1_SelectedCellsChanged" CellEditEnding="Grid1_CellEditEnding" LoadingRow="Grid1_LoadingRow" SelectionMode="Extended">
            <DataGrid.RowHeaderTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">  
                        <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                                      AncestorType={x:Type DataGridRow}}, 
                                      Path=Item.Time}" FontSize="16"  />
                        <TextBlock Text="00" Foreground="#9493CF"   />
                    </StackPanel>
                </DataTemplate>
            </DataGrid.RowHeaderTemplate>
            <DataGrid.Style>
                <Style TargetType="DataGrid">
                    <Setter Property="AlternatingRowBackground" Value="LightYellow"/>
                </Style>
            </DataGrid.Style>
            <DataGrid.Columns>
                <DataGridTextColumn Header="Sunday" Binding="{Binding Sunday}" />
                <DataGridTextColumn Header="Monday" Binding="{Binding Monday}" />
                <DataGridTextColumn Header="Tuesday" Binding="{Binding Tuesday}" />
                <DataGridTextColumn Header="Wednesday" Binding="{Binding Wednesday}" />
                <DataGridTextColumn Header="Thursday" Binding="{Binding Thursday}" />
                <DataGridTextColumn Header="Friday" Binding="{Binding Friday}" />
                <DataGridTextColumn Header="Saturday" Binding="{Binding Saturday}" />
            </DataGrid.Columns>
            <DataGrid.ContextMenu>
                <ContextMenu x:Name="LeftClickMenu">
                    <MenuItem Header="New Appointment" Click="MenuItem_Click"/>                  
                    <Separator/>
                    <MenuItem Header="Exit"/>
                </ContextMenu>
            </DataGrid.ContextMenu>
        </DataGrid>
Posted

1 solution

You should use DataGridTemplateColumn instead of a DataGridTextColumn like this :

XML
<DataGrid>
                                                            <DataGrid.Columns>
                                                                <DataGridTemplateColumn>
                                                                    <DataGridTemplateColumn.CellEditingTemplate>
                                                                        <DataTemplate>
                                                                            <DataGrid />
                                                                        </DataTemplate>
                                                                    </DataGridTemplateColumn.CellEditingTemplate>
                                                                    <DataGridTemplateColumn.CellTemplate>
                                                                        <DataTemplate>
                                                                            <TextBlock />
                                                                        </DataTemplate>
                                                                    </DataGridTemplateColumn.CellTemplate>
                                                                </DataGridTemplateColumn>
                                                            </DataGrid.Columns>
                                                        </DataGrid>


Hope this helps
 
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