DataGrid: alter programmatically the grouped column collection

Posted by: abellisomi on 14 March 2018, 10:07 am EST

    • Post Options:
    • Link

    Posted 14 March 2018, 10:07 am EST

    Hello,

    is there a way to set programmatically what the grouped columns are?

    I want to group certain columns by default, and the user can edit the default.

    I tried to modify the GroupedColumns array but the property is read only and fixed size.

  • Posted 15 March 2018, 12:09 am EST

    Hello,

    You can programmatically group by any column by using C1Datagrid’s GroupBy method as follows:```

    dataGrid.GroupBy(dataGrid.Columns[ColumnName], C1.WPF.DataGrid.DataGridSortDirection.Ascending);

    Also, attached is sample, if you wish to see it in implementation.
    
    Regards,
    Ruchir Agarwal
    [zip filename="C1Datagrid_GroupedColumns.zip"]public\uploads\e62603ef1ba9a804d44879b91c23abdc1521119192066.zip[/zip]
  • Posted 16 March 2018, 12:30 am EST

    Very nice thank you

  • Posted 19 January 2020, 2:44 pm EST

    Is there a way to prevent users from changing groups once they have been set up in code?

  • Posted 20 January 2020, 7:29 pm EST

    Hi,

    How are the users able to change the grouping? Are they currently dragging & dropping column headers to the Grouping Area to perform grouping?

    In that case, you can set the CanUserGroup property to False. This would however, prevent the users from grouping irrespective of whether/not the groups have been set up in code.

    So, if you want to conditionally prevent the users from grouping, then you should set CanUserGroup property to True and handle the ColumnHeaderDragStarted event, as follows:```

    private void dataGrid_ColumnHeaderDragStarted(object sender, C1.WPF.C1DragStartedEventArgs e)

    {

    if(dataGrid.GroupedColumns.Count()>0)

    {

    e.DragHelper.Complete();

    }


    }

    Ruchir
  • Posted 21 January 2020, 2:21 am EST

    That sounds like a good solution, thanks a lot Ruchir

Need extra support?

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

Learn More

Forum Channels