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

[Solved] GridViewToggleRowDetailsColumn Visibility

6 Answers 688 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.
Paurav
Top achievements
Rank 1
Paurav asked on 13 Sep 2010, 08:52 PM
Hi,

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:

        private void GridView_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            GridViewRow row = e.Row as GridViewRow;
            if (row != null)
            {
                row.IsExpandable = false; //This is to test if "+" collapses
            }
        }

Thanks

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 14 Sep 2010, 07:37 AM
Hi Paurav,

You may take a look at this blog post  for a reference.
Let me know if it corresponds to your requirements and project settings. 

Greetings,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Paurav
Top achievements
Rank 1
answered on 18 Oct 2010, 08:08 PM
We are doing the expansion a bit differently because we have multiple object/properties as children of the details and details data template are little more complicated. I have modified your solution to show how we are showing details. Please let me know how I can hide the GridViewToggleRowDetailsColumn.

Xaml:
<UserControl x:Class="BindingToIsExpandable_SL.MainPage"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             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
0
Maya
Telerik team
answered on 21 Oct 2010, 01:37 PM
Hello 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Paurav
Top achievements
Rank 1
answered on 21 Oct 2010, 04:09 PM

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

0
Veselin Vasilev
Telerik team
answered on 21 Oct 2010, 04:19 PM
Hi 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Prakash
Top achievements
Rank 1
answered on 26 Oct 2010, 02:28 PM
Code used: Source Code in Blog Post

When I use ExpandAllHierarchyItems i get all the Rows with (+)  with empty grid.

How can i solve this issue..

 

Tags
GridView
Asked by
Paurav
Top achievements
Rank 1
Answers by
Maya
Telerik team
Paurav
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Prakash
Top achievements
Rank 1
Share this question
or