This is a migrated thread and some comments may be shown as answers.
Show and hide expand button dynamically
3 Answers 57 Views
This is a migrated thread and some comments may be shown as answers.
alvin
Top achievements
Rank 1
alvin asked on 15 Aug 2011, 03:37 PM
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.

3 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 15 Aug 2011, 03:45 PM
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 >>

0
alvin
Top achievements
Rank 1
answered on 15 Aug 2011, 03:55 PM
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


0
Vanya Pavlova
Telerik team
answered on 15 Aug 2011, 06:08 PM
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 >>

Asked by
alvin
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
alvin
Top achievements
Rank 1
Share this question
or