I am using a hierachical RadGridView and when i expand a GridViewRow, the first time it expands, the childDataControls list count is 0. If i collapse the row , the event is fired again and the childDataControls list is populated. I need to get the row's childDataControls on the first expand event, is it possible?
I'm trying to select a row's childDataControl (RadGridView) the first time that row is expanded.
What would a different approach be?
private void myGrid_RowIsExpandedChanged(object sender, RowEventArgs e)
{
GridViewRow r = e.Row as GridViewRow;
var childControls = r.ChildDataControls;
}
4 Answers, 1 is accepted
The reason why the row.childDataControls is empty when you first expand the row is that the child control is still not created. Generally the hierarchical items are loaded on demand when they are expanded. Once the control has been created you may access it.
Why do you need to access the childDataControl? May you please specify more details on what your scenario is?
Didie
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

I have the same problem that the ChildDataControls collection is empty. What I am trying to do is to enable row reordering (drag and drop) on the child data grid of my hierarchy (RadGridView). My code is as follows:
private void rgvGroups_RowLoaded(object sender, RowLoadedEventArgs e)
{
GridViewRow row = e.Row as GridViewRow;
if (row != null)
{
row.IsExpanded = true;
if (row.ChildDataControls.Count > 0)
{ RowReorderBehavior.SetIsEnabled(row.ChildDataControls[0], true);
}
}
}
Is there a different event that I should use, or is there a different way to enable row reordering in a hierarchy?
Thank you,
Vlad
How do you define your hierarchy GridView?
You could set the RowReaderBehavior when you define it. For example:
<
telerik:RadGridView.HierarchyChildTemplate
>
<
DataTemplate
>
<
telerik:RadGridView
ItemsSource
=
"{Binding Players}"
local:RowReorderBehavior.IsEnabled
=
"True"
>
</
telerik:RadGridView
>
</
DataTemplate
>
</
telerik:RadGridView.HierarchyChildTemplate
>
I hope that this is helpful.
Regards,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Thank you for your reply. I am defining my hierarchy exactly like in your example, but unfortunately enabling the row reorder behavior in xaml does not seem to work (it compiles and runs fine but the grid does not allow reordering). What I ended up doing is to enable it in the Loaded event of the child grid and then rebind that grid:
private void rgvDocuments_Loaded(object sender, RoutedEventArgs e)
{
RadGridView grid = e.Source as RadGridView;
RowReorderBehavior.SetIsEnabled(grid, false);
RowReorderBehavior.SetIsEnabled(grid, true);
//rebind gird so that the row reorder event handlers are hooked up properly
grid.Rebind();
}
I'm not sure if this is the best approach but it's the only one I could get to work.
Vlad