This is a migrated thread and some comments may be shown as answers.

RadGridView HierarchyChildTemplate and State

2 Answers 99 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 22 Feb 2012, 06:16 PM

Our use case is to have a grid which can be expanded to show more granular details including child data, similar to your samples.  One of the catches is that not all the data is available in the ItemsSource collection of objects.  To avoid what will appear as a memory leak over time, we chose to load / unload the child data as needed.  We have success using the RowIsExpandedChanged event to manage the data.  We also use the HierarchyChildTemplate and specify the DataTemplate as a collective group of controls and UserControls.  

One of these UserControls is another GridView to present a collection of child details of the parent record.  This user control will subscribe to events and update its grid with additions and edits.  To wire up these events we use an identifier passed to the control via a DependancyProperty.  We have found that once a row has been expanded and the UserControl initialized for those events it will remain in effect even when the row is collapsed.  To confirm this we wired up the CoerceValueCallback on the DependancyProperty and it is not getting fired when we expand the row after the first time.  We understand that due to the virtualization rows are destroyed when out of view. So, in turn, just the event of the user scrolling around will perform a sort of "clean up."  As good practice of not leaving resources in use when no longer visible, is there some property we should be setting to destroy the HierarchyChildTemplate when the row is collapsed? 

Here are some segments of code we are using. 

<Telerik:RadGridView Grid.Row="1" x:Name="radGridViewMain" ItemsSource="{Binding Incidents}"

 IsReadOnly="True" AutoGenerateColumns="False" CanUserFreezeColumns="False"

RowIsExpandedChanged="radGridViewMain_RowIsExpandedChanged"

 ShowGroupPanel="True" RowIndicatorVisibility="Collapsed"

TelerikGridViewHeaderMenu:GridViewHeaderMenu.IsEnabled="True"

 CustomFilter:CustomFilterBehavior.TextBox="{Binding ElementName=textBoxFilter}">

 

 

 

<Telerik:RadGridView.ChildTableDefinitions>

<Telerik:GridViewTableDefinition>

<Telerik:GridViewTableDefinition.Relation>

<TelerikWindowsData:PropertyRelation ParentPropertyName="PrimaryKey"/>

</Telerik:GridViewTableDefinition.Relation>

</Telerik:GridViewTableDefinition>

</Telerik:RadGridView.ChildTableDefinitions>

<Telerik:RadGridView.HierarchyChildTemplate>

<DataTemplate>

<Controls:ChildItems PrimaryKey="{Binding PrimaryKey}"  />

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Nedyalko Nikolov
Telerik team
answered on 27 Feb 2012, 01:50 PM
Hello,

Unfortunately RadGridView does not have a suitable API for such custom recycling. However you could achieve such behavior with a few lines of code. All you have to do is to handle RadGridView.RowIsExpandedChanged and clear the content of the HierarchicalChildPresenter.

private void clubsGrid_RowIsExpandedChanged(object sender, Telerik.Windows.Controls.GridView.RowEventArgs e)
        {
            GridViewRow row = e.Row as GridViewRow;
            if (row != null && !row.IsExpanded)
            {
                var test = row.ChildrenOfType<ContentPresenter>().Where(cp => cp.Name == "PART_HierarchyChildPresenter").First() as ContentPresenter;
                if (test != null)
                {
                    test.Content = null;
                }
            }
        }

Let me know if this does not help.

Kind regards,
Nedyalko Nikolov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Paul
Top achievements
Rank 1
answered on 27 Feb 2012, 03:01 PM
This helps.

Thank you very much.
Tags
GridView
Asked by
Paul
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Paul
Top achievements
Rank 1
Share this question
or