RadGridView Group IsExpanded

1 Answer 48 Views
GridView
Michael
Top achievements
Rank 1
Michael asked on 04 Nov 2021, 05:56 AM | edited on 04 Nov 2021, 05:58 AM

Hello Forum!

I have the following method in a RadGridView-behavior which expands all groups in my RadGridView (just like method ExpandAllGroups()):


      private static void onExpandAllCommandBoolChanged( DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
      {
         var radGridView = ( (RadGridViewExpandAndCollapseAllGroupingsCommandBehavior) dependencyObject ).AssociatedObject;

         var groups = radGridView?.Items.Groups;
         if( groups == null )
            return;
         foreach( var group in groups )
         {
            radGridView.ExpandGroup( (IGroup)group );
         }

         // easier: ((RadGridViewExpandAndCollapseAllGroupingsCommandBehavior)dependencyObject).AssociatedObject.ExpandAllGroups();
      }

My task is to expand the same RadGridView-groups after a reload of the RadGridView-data that were expanded before the reload.
To accomplish this, i need the IsExpanded-property of the RadGridView-group, but it isn't available in type Group.

Which datatype can I use to get the IsExpanded-property?
I use WPF and MVVM.

Thank you!

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 08 Nov 2021, 02:14 PM

Hello Michael,

Indeed, the Group object doesn't contain information about the expanded state of the group. This is hold by the visual element behind the group (GroupHeaderRow). It exposes an IsExpanded property which you can use in order to determine if the group is expanded. You can use the GroupRowIsExpandedChanged event of RadGridView in order to cache the current expand state of the group.

I hope that information helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Michael
Top achievements
Rank 1
commented on 09 Nov 2021, 11:00 AM

Hello Martin, 

 

thank you, I could make it work in the code behind with the GroupRowIsExpandedChanged- and DataLoaded-events:


      private void radGridView_OnGroupRowIsExpandedChanged( object sender, GroupRowEventArgs e )
      {
         if( !(e.Row is GridViewGroupRow expandedGroup) )
            return;

         if( expandedGroup.IsExpanded )
         {
            if( !gridViewGroupRowList.Contains( expandedGroup ) )
               gridViewGroupRowList.Add( expandedGroup );
         }
         else
         {
            gridViewGroupRowList.Remove( expandedGroup );
         }
      }

      private void radGridView_OnDataLoaded( object sender, EventArgs e )
      {
         GridViewDataControl dataControl = (GridViewDataControl)sender;
         foreach( var gridViewGroupRow in gridViewGroupRowList )
         {
            dataControl.ExpandGroup( gridViewGroupRow.Group );
         }
      }
If you copy my solution: Please note that the groups may change when other data is loaded into the RadGridView. In this case, above code will be faulty, because the list gridViewGroupRowList contains the expanded groups from the old RadGridView data.
Martin Ivanov
Telerik team
commented on 11 Nov 2021, 01:09 PM

Thank you for sharing your solution.

About the situation where the list contains groups from the old ItemsSource data of RadGridView, you can use the following approach. If the new data doesn't contain groups which should be expanded (from the previous data) you can simply clear the "gridViewGroupRowList". Otherwise, instead of saving the entire GridViewGroupRow, you can save some ID (for example the Key of the Group object) and use it when needed to expand the group.

Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or