Datagrid - DataGridGroupRow - control over expand / collapse

Posted by: appmod on 7 August 2017, 5:11 pm EST

    • Post Options:
    • Link

    Posted 7 August 2017, 5:11 pm EST

    I have a datagrid with itemsource bound to an observable collection.

    If the user uses the grouping feature, and collapses 1 (or more) groups…

    But in the background (on timer) we have newer records arriving in to our collection…

    The datagrid will always refresh with all groups expanded.

    I need a way to remember which group values are collapsed, and after each refresh (to itemsource) I can re-collapse the correct entries (assuming they still exist of course).

    This person also had a similar question:

    http://our.componentone.com/groups/silverlight/studio-for-silverlight/forum/topic/datagrid-refresh-data

    Any tips/ suggestions (or can it be done)?

    Thanks in advance.

    -michael

  • Posted 7 August 2017, 5:11 pm EST

    I think you can save the ‘GroupRowsVisibility’ values using a dictionary and apply those values later on after the refresh. So, try something like this to save the GroupRowsVisibility values:-

    [csharp] Dictionary<int, Visibility> rowvisibilityvalues = new Dictionary<int, Visibility>();

    foreach (var row in grid.Rows)

    {

    if (row.Type == DataGridRowType.Group)

    {

    rowvisibilityvalues[row.Index] = (row as DataGridGroupRow).GroupRowsVisibility;

    }

    }[/csharp]

    You can manually apply the values like this:-

    [csharp]foreach (var row in GridA.Rows)

    {

    if (row.Type == DataGridRowType.Group)

    {

    (row as DataGridGroupRow).GroupRowsVisibility = rowvisibilityvalues[row.Index] ;

    }

    }[/csharp]

    Let me know if you face any further issues/questions.

    Thanks

  • Posted 7 August 2017, 5:11 pm EST

    Wondering if this is still the only way to keep groups from auto-expanding after a refresh.

    If so, are there recommended Grid events to perform this manual saving / retrieving of grid settings?

    Thanks.

  • Posted 7 August 2017, 5:11 pm EST

    How is the refresh occurring in your case? Is it a change in the bound ItemsSource or what?

    If you are changing the itemssource manually, you can update the ItemsSource between the above methods.

    Regards

  • Posted 20 January 2020, 1:06 pm EST

    C1upkar_s, this does not seem to work. If I read the property

    GroupRowsVisibility
    I always get
    Visible
    , regardless of the situation for the group, expanded or collapsed doesn’t matter.

    Any idea?

    Thanks,

    A.

  • Posted 21 January 2020, 7:30 am EST

    Hi,

    I have prepared for you a solution that stores the expand/collapse state of grouped rows in C1DataGrid. For details, please refer the attached application.

    Hopefully this should help.

    Regards,

    Ruchir

    StoreGroupInfo_C1DataGrid.zip

Need extra support?

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

Learn More

Forum Channels