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

User control in expanded row

5 Answers 85 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
krisdoff
Top achievements
Rank 1
krisdoff asked on 05 Jan 2012, 04:08 PM
Hi there,

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

Sort by
0
Dimitrina
Telerik team
answered on 06 Jan 2012, 08:59 AM
Hi Chris,

 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. 

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
krisdoff
Top achievements
Rank 1
answered on 06 Jan 2012, 06:16 PM
Hi Didie,

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
0
Dimitrina
Telerik team
answered on 09 Jan 2012, 08:52 AM
Hello 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.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
krisdoff
Top achievements
Rank 1
answered on 09 Jan 2012, 10:44 AM
Hi Didie,

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
0
Dimitrina
Telerik team
answered on 09 Jan 2012, 02:09 PM
Hi 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.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
krisdoff
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
krisdoff
Top achievements
Rank 1
Share this question
or