I am trying to achieve a grid where when a row is expanded it shows a user control that takes an id from the expanded row to populate itself. I only want the control to populate itself when the row is expanded for performance reasons.
Could you outline the best approach for this?
Many thanks
5 Answers, 1 is accepted
Do you use the RowDetails for the hierarchy?
If so, then you can attach to the RowDetailsVisibilityChanged event which will be fired each time the user expands or collapses the row details. You can check this from the event arguments by reading e.Visibility. Then you can load your control each time a row detail is expanded.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Thanks for your response. I am probably a bit confused as how to reference the specific control to cause it to load its data. This is what I have:
RowDetailsVisibilityChanged event:
if (e.Visibility == Visibility.Visible)
{
ProductCardView theCard = e.DetailsElement.FindName("cardView") as ProductCardView;
theCard.LoadData(((ProductSummary)e.Row.Item).Product.prID);
}
//XAML
<telerik:RadGridView.RowDetailsTemplate>
<DataTemplate>
<views:ProductCardView x:Name="cardView" />
</DataTemplate>
</telerik:RadGridView.RowDetailsTemplate>
Where ProductCardView is a simple user control whos LoadData method takes a product id to load its data with.
Basically FindNAme always returns null
Note, if I replace my ProductCardView class with a standard control like a button, I can find that control. ProductCardView ultimately inherits from UserControl, I have another class which inherits from ContentControl and it finds that. If I create default UserControl and try to find that, no joy.
What are the prerequsities for user controls to be located in this manner?
I don't know if it helps but I also noticed that e.Row.DetailsTemplate is null when stepping through RowDetailsVisibilityChanged
What am I doing wrong?
Many thanks
Chris
The RowDetails are loaded on demand. So the UserConrol will be loaded once the parent node has been expanded. You could perform a little test by checking when its loaded method is fired.
The DataContext of the UserControl is the DataContext of the expanded row. Then in the loaded event you could call the LoadData method with the appropriate Product.prID.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I apologise, I am not sure I understand how this assists me with my problem.
To simplify my current issue, if you create a default user control and reference it in the RowDetailsTemplate:
<telerik:RadGridView.RowDetailsTemplate>
<DataTemplate>
<aurum:TestMe x:Name="cardView"/>
</DataTemplate>
</telerik:RadGridView.RowDetailsTemplate>
And then in the RowDetailsVisibilityChanged event tryo to find that control, it cant.
private void gvwProducts_RowDetailsVisibilityChanged(object sender, Telerik.Windows.Controls.GridView.GridViewRowDetailsEventArgs e)
{
if (e.Visibility == Visibility.Visible)
{
e.DetailsElement.FindName("cardView"); <-------- Always returns null;
}
}
If I can solve that I think I have a complete solution
Thanks
Chris
You cannot find the "cardView" because the e.DetailsElements is the "cardView". You could check the value for "e.DetailsElement.Name".
By the FindName(string) method you could find a control inside the details element "aurum: TestMe".
If this is not what you have, please let me know what is the value of e.DetailsElement.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>