Access Child Datagrid in code behind

Posted by: Swapnil.Walwadkar on 14 May 2018, 4:40 pm EST

    • Post Options:
    • Link

    Posted 14 May 2018, 4:40 pm EST

    Hello,

    I am using C1 DataGrid in my WPF project.

    I have implemented hierarchical DataGrid using RowDetailsTemplate. I would like to know how we can access Child Datagrid from code behind. (I am trying to Expand/Collapse both Parent Grid and Child Grid on a single button click)

  • Posted 15 May 2018, 6:32 pm EST

    Hello,

    For that you need to access the child grid using datagrid.Rows[rowIndex].DetailPresenter.Content and then set the child grid’s DetailsVisibility property to Visible/Collapsed for Expand/Collapse respectively, as follows:

    if (gridCategories.Rows[0].DetailsPresenter !=null)
    {
           var childGrd = gridCategories.Rows[0].DetailsPresenter.Content as C1.WPF.DataGrid.C1DataGrid;
           if (flagCollapse)
           {
                 flagCollapse = false;
                 childGrd.Rows[2].DetailsVisibility = Visibility.Collapsed;
           }
           else
           {
                flagCollapse = true;
                childGrd.Rows[2].DetailsVisibility = Visibility.Visible;
           }
    }
    
    

    Please refer attached sample application.

    Thanks,

    RuchirNestedDataGrid_expand.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels