I'm using a Gridview which displays the RowDetailsTemplate when the "+" is clicked. I would like the "+" to be collapsed when there are no details. I'm trying to do this by setting the IsExpandable property of the row to false but it's not hiding the "+". What am I missing? Following is the code:
Thanks
6 Answers, 1 is accepted
You may take a look at this blog post for a reference.
Let me know if it corresponds to your requirements and project settings.
Maya
the Telerik team
Xaml:
<UserControl x:Class="BindingToIsExpandable_SL.MainPage" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:my="clr-namespace:BindingToIsExpandable_SL" mc:Ignorable="d" d:DesignHeight="700" d:DesignWidth="700"> <UserControl.Resources> <my:MyViewModel x:Key="MyViewModel"/> </UserControl.Resources> <Grid DataContext="{StaticResource MyViewModel}"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.Resources> <DataTemplate x:Key="RowDetailsTemplate"> <telerik:RadGridView Name="playersGrid" ItemsSource="{Binding Players}" AutoGenerateColumns="False"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding Number}"/> <!--<telerik:GridViewDataColumn DataMemberBinding="{Binding Position}"/>--> <telerik:GridViewDataColumn DataMemberBinding="{Binding Country}"/> </telerik:RadGridView.Columns> </telerik:RadGridView> </DataTemplate> </Grid.Resources> <telerik:RadGridView Grid.Row="0" Name="clubsGrid" ItemsSource="{Binding Clubs}" AutoGenerateColumns="False" RowIndicatorVisibility="Collapsed" RowDetailsTemplate="{StaticResource RowDetailsTemplate}" Margin="5"> <i:Interaction.Behaviors> <my:IsExpandableBehavior IsExpandableSourcePropertyName="Players.Count" /> </i:Interaction.Behaviors> <telerik:RadGridView.Columns> <telerik:GridViewToggleRowDetailsColumn /> <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding Established}" Header="Est." DataFormatString="{}{0:yyyy}"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}" Header="Stadium" DataFormatString="{}{0:N0}"/> </telerik:RadGridView.Columns> </telerik:RadGridView> </Grid> </UserControl>Code behind:
using System.Windows.Controls;using Telerik.Windows.Controls.GridView;using System.Windows.Data;using Telerik.Windows.Data;using Telerik.Windows.Controls;namespace BindingToIsExpandable_SL{ public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } }}Thanks,
Paurav
Following the code-snippet above, what you need to do is to remove the definition of the GridViewToggleRowDetailsColumn in the clubsGrid, set its property RowDetailsVisibilityMode to "VisibleWhenSelected and handle the LoadingRowDetails as follows:
private void clubsGrid_LoadingRowDetails(object sender, GridViewRowDetailsEventArgs e){ var row = e.Row as GridViewRow; Club club = this.clubsGrid.ItemContainerGenerator.ItemFromContainer(row) as Club; if(club.Players.Count == 0) { row.DetailsVisibility = Visibility.Collapsed; }}All the best,
Maya
the Telerik team
Hi Maya,
This solves one problem but creates another. The user doesn't know which row has details and which one doesn't. So they have to click on each row to see if there is anything in the row. Is there a way I can show GridViewToggleRowDetailsColumn and reach the item in that GridViewToggleRowDetailsColumn when each row loads and make it inisible based on the binding on the row?
Thanks,
Paurav
Please check this project on how to accomplish the task. It is for WPF, but with small changes you should be able to make it work for Silverlight.
Let me know if you face any problems.
All the best,
Veselin Vasilev
the Telerik team
When I use ExpandAllHierarchyItems i get all the Rows with (+) with empty grid.
How can i solve this issue..