Column resize in nested C1DataGrid

Posted by: Swapnil.Walwadkar on 19 September 2023, 6:10 pm EST

    • Post Options:
    • Link

    Posted 19 September 2023, 6:10 pm EST - Updated 19 September 2023, 6:15 pm EST

    Hello ComponentOne Team,

    We have one query and need your support on the same.

    we are using C1DataGrid and have made it a nested grid. We have a requirement of resizing the column of that grid. “Image 1.jpeg” is the screenshot of that grid.

    But when we resize any column, only the parent grid column gets resized and child grid column width stays as it is. Image 2.jpeg" is the screenshot of the same.

    Could you please let us know, how resizing of nested grid columns can be synchronized.

  • Posted 21 September 2023, 12:46 am EST

    Hi Swapnil,

    It seems that you are applying grouping on a nested datagrid. The behavior shown in this case seems to be a desired behaviour of the datagrid control. The column resizing of the parent datagrid should not affect the child grid because the number of columns in the C1DataGrid (contained in the RowTemplate) and the parent C1DataGrid, need not be the same.

    However, based on your use case scenario you can consider a workaround to handle parent grid’s ColumnResized event to change the column width of the nested grid as shown in the following code snippet:

    private void gridCategories_ColumnResized(object sender, DataGridColumnEventArgs e){
        foreach(DataGridRow row in ((C1DataGrid)sender).Rows)
    {      
            if(row.DetailsPresenter != null && row.DetailsPresenter.Content is C1DataGrid dg
                && e.Column.Index < dg.Columns.Count)
            {
                dg.Columns[e.Column.Index].Width = e.Column.Width;
                dg.Refresh();
            }
        }
    }

    Kindly refer to the attached sample for full implementation. (See DataGridNested.zip)

    Thanks & Regards,

    Aastha

Need extra support?

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

Learn More

Forum Channels