Show and hide expand button dynamically

4 posts, 0 answers
  1. alvin
    alvin avatar
    7 posts
    Member since:
    May 2011

    Posted 15 Aug 2011 Link to this post

    Hi,

    In the custom hierarchy demo it shows how to show and hide the expand button during row loaded event. My question is if the users are able to add and remove child rows though the user interface after the gridview is loaded and I don't want to display the expand button if there are no child rows, is there a way to achieve it? 

    Thanks.
  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 15 Aug 2011 Link to this post

    Hi Alvin,

     
    Have you checked this demo "Custom Hierarchy"? The same approach is applicable in WPF as well. 


    Kind regards,
    Vanya Pavlova
    the Telerik team

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

  3. UI for WPF is Visual Studio 2017 Ready
  4. alvin
    alvin avatar
    7 posts
    Member since:
    May 2011

    Posted 15 Aug 2011 Link to this post

    Hi, that's exactly the sample I was referring to in my first post, in the example code it is using RowLoaded event to handle the show/hide logic, however in my example, say the datasource of a GridVew is a Observable collection called AllItems, and each item has a Child observable collection called ChildItems.

    Say there is a button called "Clear Child Items" for each row and when clicked it will clear the ChildItems property for the current row item, and I want to hide the expend button afterwards since there are no child items to show. However the RowLoaded event is not invoked in this case. Can you point me in a direction? Thanks


  5. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 15 Aug 2011 Link to this post

    Hi Alvin,

     

    Thank you for the details about your requrement! In this way within the Button Click event handler you may get the parent row using ParentOfType extension method based on your custom logic and finally set the IsExpandable property to False. The following is just a simple example, which demonstrates how this can be achieved:


    telerik:GridViewColumn>
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadButton Content="Clear Child Items" Click="RadButton_Click" />
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
                    <telerik:GridViewColumn>


    private void RadButton_Click(object sender, RoutedEventArgs e)
            {
                var row = (sender as RadButton).ParentOfType<GridViewRow>();
                if(row != null)
                {
                      Orders order = row.DataContext as Orders;
                    if (row != null && order != null)
                    {
                        row.IsExpandable = order.ShipCountry == "France" || order.ShipCountry == "Brazil";
                    }
                    else
                    {
                        row.IsExpandable = false;
                    }


                }
                
            }



    Best wishes,
    Vanya Pavlova
    the Telerik team

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

Back to Top