User control in expanded row

6 posts, 0 answers
  1. krisdoff
    krisdoff avatar
    12 posts
    Member since:
    Nov 2006

    Posted 05 Jan 2012 Link to this post

    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
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 Jan 2012 Link to this post

    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 >>

  3. DevCraft banner
  4. krisdoff
    krisdoff avatar
    12 posts
    Member since:
    Nov 2006

    Posted 06 Jan 2012 Link to this post

    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
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 09 Jan 2012 Link to this post

    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 >>

  6. krisdoff
    krisdoff avatar
    12 posts
    Member since:
    Nov 2006

    Posted 09 Jan 2012 Link to this post

    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
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 09 Jan 2012 Link to this post

    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 >>

Back to Top
DevCraft banner