Select Template in hierarchical gridview

3 posts, 1 answers
  1. Cesar
    Cesar avatar
    11 posts
    Member since:
    Dec 2010

    Posted 11 Sep 2011 Link to this post

    Hello Guys

    As you can see the attached file, I have a gridview with 4 hierarchical views, I need that when the user click one of the tabs of the hierarchical view, and other row is expanded the selected tab view will be the previous selected. And if more of 1 row is expanded and the user change the  hierarchical view, in all the expanded rows change the selected tab view to the selected for the user.

     I tried to make it with the RadGridView1_ChildViewExpanding Event but i didnt find the Select Tab Property,
     in the hirarchical view

    Private Sub RadGridView1_ChildViewExpanding(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.ChildViewExpandingEventArgs) Handles RadGridView1.ChildViewExpanding
            Dim stemplate As String
            If e.IsExpanded = False Then
                For Each row As GridViewRowInfo In RadGridView1.Rows
                    If (row.IsExpanded = True) Then
                        stemplate = DirectCast(row, Telerik.WinControls.UI.GridViewHierarchyRowInfo).ActiveView.ViewTemplate.Caption
                        Exit For
                    End If
            End If
        End Sub
  2. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 14 Sep 2011 Link to this post

    Hello Cesar,

    Please take a look at the following full example:
    using System.Linq;
    using System.Windows.Forms;
    using Common;
    using Telerik.WinControls.UI;
    public partial class Form1 : Form
        private RadGridView _radGridView1 = GridViewHelper.CreateGridView();
        private int _selectedViewIndex;
        public Form1()
            var list = DataSources.GetComplexDataSource(20);
            _radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None;
            _radGridView1.DataSource = list.Persons;
            var carsTemplate = new GridViewTemplate();
            carsTemplate.DataSource = list.Cars;
            carsTemplate.Caption = "Cars";
            var carRelation = new GridViewRelation(_radGridView1.MasterTemplate);
            carRelation.ChildTemplate = carsTemplate;
            var apartmentsTemplate = new GridViewTemplate();
            apartmentsTemplate.DataSource = list.Apartments;
            var apartmentRelation = new GridViewRelation(_radGridView1.MasterTemplate);
            apartmentsTemplate.Caption = "Apartments";
            apartmentRelation.ChildTemplate = apartmentsTemplate;
            _radGridView1.CurrentViewChanged += new GridViewCurrentViewChangedEventHandler(_radGridView1_CurrentViewChanged);
            _radGridView1.ChildViewExpanding += new ChildViewExpandingEventHandler(radGridView1_ChildViewExpanding);
        private void _radGridView1_CurrentViewChanged(object sender, GridViewCurrentViewChangedEventArgs e)
            if (_radGridView1.Templates.IndexOf(e.NewView.ViewTemplate) == -1)
            _selectedViewIndex = _radGridView1.Templates.IndexOf(e.NewView.ViewTemplate);
            _radGridView1.Rows.Where(r => r.IsExpanded).Cast<GridViewHierarchyRowInfo>().ToList().ForEach(r => r.ActiveView = r.Views[_selectedViewIndex]);
        private void radGridView1_ChildViewExpanding(object sender, ChildViewExpandingEventArgs e)
            if (!e.IsExpanded)
                e.ParentRow.ActiveView = e.ParentRow.Views[_selectedViewIndex];

    Best Regards,
    Emanuel Varga
  3. Cesar
    Cesar avatar
    11 posts
    Member since:
    Dec 2010

    Posted 02 Oct 2011 Link to this post

    Thanks Emanuel!!!!!!
Back to Top