Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am designing a wpf application.I got a requirement to design Parent child grid. I am able to show the child grid in RowDetailsVisibilityChanged event. But I want to fire that event when I click a expand button in my grid, Please provide me the code to shoe the child grid in click event.... Please see my code to give the correct and appropriate answer


XML
<DataGrid  >
                <DataGrid.Columns>
                    <DataGridTemplateColumn Header="C">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                 <StackPanel>
                        <Button x:Name="btnCollapse"  ToolTip="Expand" Foreground="Black" Background="Transparent" BorderBrush="Transparent" Tag="{Binding LineItemKitsID}"   >
                                        <Image Source="../images/Plus.png" Cursor="Hand" Height="20" Width="15" ></Image>
                                    </Button>
                                </StackPanel>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                    <DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="160*" Binding="{Binding GroupName}" Header="Group Name"  Foreground="Black">
                    </DataGridTextColumn>


                </DataGrid.Columns>
    <DataGrid.RowDetailsTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <DataGrid Name="NestedDG">
                    <DataGrid.Columns>
                        <DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="230" Binding="{Binding LineItem}" Header="Line Item"  Foreground="Black">
                        </DataGridTextColumn>
                      


                        <DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="110" Binding="{Binding EffectiveDate}" Header="Effective Date"  Foreground="Black">
                        </DataGridTextColumn>

                       
                   
                    </DataGrid.Columns>

                </DataGrid>
            </StackPanel>
        </DataTemplate>
    </DataGrid.RowDetailsTemplate>




c# code :
It will fire in
RowDetailsVisibilityChanged
.. but i want to fire in button click

C#
protected void ParentDG_RowDetailsVisibilityChanged(object sender, DataGridRowDetailsEventArgs e)
           {
            DataGrid nestedGrid = (DataGrid)e.DetailsElement.FindName("NestedDG");
              if (e.Row.DetailsVisibility == Visibility.Visible)
              {
                  nestedGrid.ItemsSource = dsKitDetails.Tables[0].DefaultView;
              }

            }
Posted
Comments
Alexander Dymshyts 7-Nov-13 9:45am    
Can you override RowDetailsVisibilityChanged?
jing567 7-Nov-13 23:44pm    
Hi Alexender,
My code is working fine in rowVisibilty Changed.... But I dont want like this because I have Edit and Delete buttons in my DataGrid..... Is there any way to get the child grid control in click event??? Please reply yar
Alexander Dymshyts 8-Nov-13 3:47am    
if your button is in gridControl, you can try yourButtonName.Parent
jing567 8-Nov-13 4:03am    
Hi,
I want to get the control of child grid in button click event.... is it possible?
Alexander Dymshyts 8-Nov-13 4:24am    
Sorry, what do you want to get on button click?

1 solution

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