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

Select Template in hierarchical gridview

2 Answers 85 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Cesar
Top achievements
Rank 1
Cesar asked on 12 Sep 2011, 12:19 AM
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
        'RadGridView1.Templates.GetTemplateByCaption(e.ParentRow.ActiveView.ViewTemplate.Caption)
        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
            Next
 
        End If
 
    End Sub

2 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 14 Sep 2011, 10:44 AM
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()
    {
        InitializeComponent();
        this.Controls.Add(_radGridView1);
        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;
        carRelation.ChildColumnNames.Add("Id");
        carRelation.ParentColumnNames.Add("CarId");
        _radGridView1.Templates.Add(carsTemplate);
        _radGridView1.Relations.Add(carRelation);
 
        var apartmentsTemplate = new GridViewTemplate();
        apartmentsTemplate.DataSource = list.Apartments;
        var apartmentRelation = new GridViewRelation(_radGridView1.MasterTemplate);
        apartmentsTemplate.Caption = "Apartments";
        apartmentRelation.ChildTemplate = apartmentsTemplate;
        apartmentRelation.ChildColumnNames.Add("Id");
        apartmentRelation.ParentColumnNames.Add("ApartmentId");
        _radGridView1.Templates.Add(apartmentsTemplate);
        _radGridView1.Relations.Add(apartmentRelation);
 
        _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)
        {
            return;
        }
 
        _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
0
Cesar
Top achievements
Rank 1
answered on 03 Oct 2011, 01:47 AM
Thanks Emanuel!!!!!!
Tags
GridView
Asked by
Cesar
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Cesar
Top achievements
Rank 1
Share this question
or